Question:
how to read this xml file in php?
another_man
2009-06-02 05:27:48 UTC
I know how to get through a XML file build like

Node Value
Node Value
...


But how to read this one ?


Node Value
Node Value
...


Node Value
Node Value
...

...


In php using DOMDocument(); and reading through with a foreach

Thanks!
Three answers:
anonymous
2009-06-02 08:15:44 UTC
Generally speaking, you create a valid XML file by specifying a root node, with varying levels of subnodes.



So, rather than the structure you show, it would be more like this:



http://msdn.microsoft.com/en-us/library/ms762271(VS.85).aspx



To traverse this document, I would use XMLReader.




$doc = new XMLReader();

$doc->open("books.xml");

while($doc->read()) {

//code to do whatever you want done here.

}

$doc->close();

?>
digits9
2009-06-02 05:38:09 UTC
$xmlDoc = new DOMDocument();



$xmlDoc->load("xml.xml");



$x = $xmlDoc->documentElement;



foreach ($x->childNodes AS $item)

{

foreach ($item->childNodes AS $y)

{

echo $y->nodeName . " = " . $y-nodeValue;

}

}



I think that something like that will solve it. Go to the site and read some more for more details on what you are trying to accomplish.
vhinz
2009-06-02 05:33:41 UTC
hi, I think you can find your solution here:



http://www.w3schools.com/php/php_xml_dom.asp





good luck :)


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...