Jump to content

Accessing simple XML elements


frobak

Recommended Posts

Hey

 

Right, have this issue with accessing simpleXML elements, i'm sure it should work, but i cant seem to get it.

 

This is the xml data. I need the model and make:

<diffgr:diffgram>
<NewDataSet>
<StdData diffgr:id="StdData1" msdata:rowOrder="0">
<MAKE>CITROEN</MAKE>
<MODEL>C3 SX</MODEL>

 

here is the php ive got:

$xml->children("diffgr", true)->diffgram->children("")->NewDataSet->StdData->MAKE;

 

Can you see where im going wrong?

 

cheers

Link to comment
https://forums.phpfreaks.com/topic/266651-accessing-simple-xml-elements/
Share on other sites

Your XML looks invalid. You have no namespace definition and do not close the diffgram, NewDataSet or StdData tags.

 

Once its valid you can retrieve the make and model using

 

$xml->children('diffgr', true)->children()->MAKE;
$xml->children('diffgr', true)->children()->MODEL;

 

Although that code is dependent on how you close your XML tags. You may need another step in there because of your NewDataSet which I see no need for at the minute.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.