Welcome to WebmasterWorld Guest from 54.196.244.45

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

SimpleXML drops inline tags?

     
8:24 am on Apr 19, 2012 (gmt 0)

Junior Member

joined:Apr 19, 2011
posts: 42
votes: 0


Suppose you have an xml-file with the following structure (taken from the php manual):

<movie>
<title>PHP: Behind the Parser</title>
<plot>
So, this <o>language</o>. It's like, a programming language. Or is it a
scripting language? All is revealed in this thrilling horror spoof
of a documentary.
</plot>
</movie>


I made one change to this code as opposed to the original, I added an <o> 'inline' tag as child of <plot>.

When I use this xml to create a SimpleXML Element the node 'plot' drops this <o> tag and it's contents (<o>language</o>. Is there anyway to either keep the tag or at least its contents?
11:34 am on Apr 19, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Apr 30, 2007
posts:1394
votes: 0


That's because you don't want the string of plot to be parsed by the XML as it is html, so one way is to use the CDATA because you don't want it to be interpreted as markup

<plot>
<![CDATA[
So, this <o>language</o>. It's like, a programming language. Or is it a
scripting language? All is revealed in this thrilling horror spoof
of a documentary.
]]>
</plot>

or you encode the characters like &lt; &gt; etc.
12:22 pm on Apr 19, 2012 (gmt 0)

Junior Member

joined:Apr 19, 2011
posts: 42
votes: 0


Bummer. The problem is I have no control over the xml. I will be getting large amounts of files with this type of markup which I need to parse :-(