SimpleXML parse

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
jwalsh
Forum Contributor
Posts: 202
Joined: Sat Jan 03, 2004 4:55 pm
Location: Cleveland, OH

SimpleXML parse

Post by jwalsh »

I'm trying to parse an XML file similar to this...

Code: Select all

<RESULTS>
<TITLE> Name1 </TITLE>
<VALUE> Name1 Value </VALUE>
<TITLE> Name2 </TITLE>
<VALUE> Name2 Value </VALUE>
<TITLE> Name3 </TITLE>
<VALUE> Name3 Value </VALUE>
<TITLE> Name4 </TITLE>
<VALUE> Name4 Value </VALUE>
</RESULTS>
SimpleXML tells me to look first for the encapsulating tag as if it were formed like this...

Code: Select all

<RESULTS>
<ITEM>
<TITLE> Name1 </TITLE>
<VALUE> Name1 Value </VALUE>
</ITEM>
<ITEM>
<TITLE> Name2 </TITLE>
<VALUE> Name2 Value </VALUE>
</ITEM>
<ITEM>
<TITLE> Name3 </TITLE>
<VALUE> Name3 Value </VALUE>
</ITEM>
<ITEM>
<TITLE> Name4 </TITLE>
<VALUE> Name4 Value </VALUE>
</ITEM>
</RESULTS>
... which would be simple to parse, but that's not what I'm given. How can I parse the first example, even though it lacks the <ITEM> tag?

Thanks,

Josh
User avatar
jwalsh
Forum Contributor
Posts: 202
Joined: Sat Jan 03, 2004 4:55 pm
Location: Cleveland, OH

Post by jwalsh »

I think I've gotten this figured out except that the xml is encoded with CDATA, so SimpleXML won't parse it... any suggestions on parsing CDATA??

Thanks,

Josh
Post Reply