|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2002-10-03 19:37 UTC] sniper@php.net
[2002-10-31 13:58 UTC] iliaa@php.net
[2002-11-01 04:12 UTC] goba@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Nov 18 10:00:02 2025 UTC |
Well, I am reading bugs of how to get the different objects and components of an xml document, and I have got a simply and fine solution that is like follow, <?php $my_xml_file = file("books.xml") or die("Error...<br>"); $dom_tree = domxml_xmltree( $my_xml_file[0] ); echo "DOMTREE loaded<br>"; print("<pre>"); print_r( $dom_tree ); print("</pre>"); echo "<br>\n"; ?> The best of it, you do not need the whole path to read the file and you get the whole description of your DOM. This is my "books.xml" file, <?xml version='1.0' encoding='UTF-8'?><books><book><Title>La peste</Title><Author>Albert Camus</Author><Price>30</Price></book></books> where the tree is listed in one only line. And here is what I get with the above php code, DOMTREE loaded DomDocument Object ( [name] => #document [url] => [version] => 1.0 [encoding] => UTF-8 [standalone] => -1 [type] => 9 [compression] => -1 [charset] => 1 [0] => 1 [1] => 8040992 [children] => Array ( [0] => DomElement Object ( [type] => 1 [tagname] => books [0] => 2 [1] => 8040880 [children] => Array ( [0] => DomElement Object ( [type] => 1 [tagname] => book [0] => 3 [1] => 8040784 [children] => Array ( [0] => DomElement Object ( [type] => 1 [tagname] => Title [0] => 4 [1] => 8040688 [children] => Array ( [0] => DomText Object ( [type] => 3 [name] => #text [content] => La peste [0] => 5 [1] => 8040608 ) ) ) [1] => DomElement Object ( [type] => 1 [tagname] => Author [0] => 6 [1] => 8040512 [children] => Array ( [0] => DomText Object ( [type] => 3 [name] => #text [content] => Albert Camus [0] => 7 [1] => 8048576 ) ) ) [2] => DomElement Object ( [type] => 1 [tagname] => Price [0] => 8 [1] => 8048512 [children] => Array ( [0] => DomText Object ( [type] => 3 [name] => #text [content] => 30 [0] => 9 [1] => 8048432 ) ) ) ) ) ) ) ) ) And that's it. I hope you like.