
array-to-domdocument
The class DOM contains these public static methods: ``` arrayToDOMDocument(array $source, $rootTagName = 'root') arrayToXMLString(array $source, $rootTagName = 'root', $formatOutput = true)
domDocumentToArray(DOMDocument $document) xmlStringToArray($xmlString) ```
Example
``` include 'DOM-2.0.php';
$source['book'][0][DOM::ATTRIBUTES]['isbn'] = '978-3-16-148410-0'; $source['book'][0][DOM::ATTRIBUTES]['publish-date'] = '2002-03-25'; $source['book'][0]['author'] = 'Author0'; $source['book'][0]['title'] = 'Title0'; $source['book'][0]['publisher'] = 'Publisher0';
$source['book'][1]['author'][0] = 'Author1'; $source['book'][1]['author'][1] = 'Author2'; $source['book'][1]['title'] = 'Title1'; $source['book'][1]['publisher'] = 'Publisher1';
$source['book'][2][DOM::ATTRIBUTES]['isbn'] = '978-3-16-148410-0'; $source['book'][2][DOM::ATTRIBUTES]['publish-date'] = '2002-03-25'; $source['book'][2][DOM::CONTENT] = 'Title2';
echo $xml = DOM::arrayToXMLString($source);
print_r(DOM::xmlStringToArray($xml));
Output:
Author0
Title0
Publisher0
Author1
Author2
Title1
Publisher1
Title2
Array
(
[book] => Array
(
[0] => Array
(
[attributes] => Array
(
[isbn] => 978-3-16-148410-0
[publish-date] => 2002-03-25
)
[author] => Array
(
[0] => Array
(
[content] => Author0
)
)
[title] => Array
(
[0] => Array
(
[content] => Title0
)
)
[publisher] => Array
(
[0] => Array
(
[content] => Publisher0
)
)
)
[1] => Array
(
[author] => Array
(
[0] => Array
(
[content] => Author1
)
[1] => Array
(
[content] => Author2
)
)
[title] => Array
(
[0] => Array
(
[content] => Title1
)
)
[publisher] => Array
(
[0] => Array
(
[content] => Publisher1
)
)
)
[2] => Array
(
[attributes] => Array
(
[isbn] => 978-3-16-148410-0
[publish-date] => 2002-03-25
)
[content] => Title2
)
)
)
```
E-mail me here to suggest an improvement: omer.hassan at stifffoot.com
Project Information
- License: MIT License
- 5 stars
- svn-based source control