DOMDocument XML issues
Posted: Mon Oct 04, 2010 9:10 pm
ok... So I am actually using curl to get XML data from another site and am successufully getting that data into a variable. problem is when I try to parse it into an array using DOMDocument.
for testing purposes I have removed the curl parts and used a manual string... here are my results
code:
The above code returns the exact array I am looking for. works 100%.
now if I change out the loadXML data like so:
it errors out with my echo of "doh!".
This is my first time using DOMDocument so I must be missing something but I just cant work it out.
when using the actual returned XML data from the curl it returns absolutely nothing. the "doh!" error doesn't go off and print_r($ssi) returns nothing at all. I even echoed out the xml string I am using before the DOM script to besure it works and it does.
The XML data being recieved is structured as so:
only real difference is there are 27,000 <Table> tags in it. thats why I tried just using 2 to see if I get what I want but ended up getting another issues that threw me off... im at a loss here.
for testing purposes I have removed the curl parts and used a manual string... here are my results
code:
Code: Select all
$doc = new DOMDocument();
if(!$doc->loadXML('<Table> <I>200</I> <Q>741</Q> <P>25.00</P> <C>25.00</C> </Table>')){
echo "doh!";
}
foreach ($doc->getElementsByTagName('Table') as $node) {
$ssi[$node->getElementsByTagName('I')->item(0)->nodeValue] = array (
'quantity' => $node->getElementsByTagName('Q')->item(0)->nodeValue,
'catalogPrice' => $node->getElementsByTagName('P')->item(0)->nodeValue,
'customerPrice' => $node->getElementsByTagName('C')->item(0)->nodeValue
);
}
print_r($ssi);
now if I change out the loadXML data like so:
Code: Select all
$doc->loadXML('<Table> <I>200</I> <Q>741</Q> <P>25.00</P> <C>25.00</C> </Table> <Table> <I>200</I> <Q>741</Q> <P>25.00</P> <C>25.00</C> </Table>')
This is my first time using DOMDocument so I must be missing something but I just cant work it out.
when using the actual returned XML data from the curl it returns absolutely nothing. the "doh!" error doesn't go off and print_r($ssi) returns nothing at all. I even echoed out the xml string I am using before the DOM script to besure it works and it does.
The XML data being recieved is structured as so:
Code: Select all
<NewDataSet>
<Table>
<I>11111</I>
<Q>741</Q>
<P>25.00</P>
<C>25.00</C>
</Table>
<Table>
<I>222222</I>
<Q>876</Q>
<P>12.00</P>
<C>12.00</C>
</Table>
</NewDataSet>