views:

282

answers:

2

When I use DOMDocument::loadXML() for my XML below I get error:

Warning: DOMDocument::loadXML() [domdocument.loadxml]: CData section not finished http://www.site.org/displayimage.php?album=se in Entity,
Warning: DOMDocument::loadXML() [domdocument.loadxml]: Premature end of data in tag image line 7 in Entity
Warning: DOMDocument::loadXML() [domdocument.loadxml]: Premature end of data in tag quizz line 3 in Entity
Warning: DOMDocument::loadXML() [domdocument.loadxml]: Premature end of data in tag quizzes line 2 in Entity
Fatal error: Call to a member function getElementsByTagName() on a non-object 

It seems to me that my CData sections are closed but still I get this error. XML looks like this:

<?xml version="1.0" encoding="utf-8"?>
<quizzes>
<quizz>
<title><![CDATA[Title]]></title>
<descr><![CDATA[Some text here!]]></descr>
<tags><![CDATA[one tag, second tag]]></tags>
<image><![CDATA[http://www.site.org/displayimage.php?album=search&amp;cat=0&amp;pos=1]]&gt;&lt;/image&gt;
<results>
<result>
<title><![CDATA[Something]]></title>
<descr><![CDATA[Some text here]]></descr>
<image><![CDATA[http://www.site.org/displayimage.php?album=search&amp;cat=0&amp;pos=17]]&gt;&lt;/image&gt;
<id>1</id>
</result>
</results>
</quizz>
</quizzes>

Could you help me discover what is the problem?

+1  A: 

I don't see any error (either the actually used XML is different form the provided, or the xml processor used (BTW, what is it?) is buggy).

I would recommend to avoid using CDATA sections. Use the following XML document, which is the same as (text-equivalent to) the provided, and much more readable:

<quizzes>
   <quizz>
      <title>Title</title>
      <descr>Some text here!</descr>
      <tags>one tag, second tag</tags>
      <image>http://www.site.org/displayimage.php?album=search&amp;amp;cat=0&amp;amp;pos=1&lt;/image&gt;
      <results>
         <result>
            <title>Something</title>
            <descr>Some text here</descr>
            <image>http://www.site.org/displayimage.php?album=search&amp;amp;cat=0&amp;amp;pos=17&lt;/image&gt;
            <id>1</id>
         </result>
      </results>
   </quizz>
</quizzes>
Dimitre Novatchev
A: 

I 've found that the problem was with passing this XML in PHP with cURL. I've sent it as normal text, and & char in this XML was interpreted as delimiter to next parameter. So when I escaped this char it started to work properly.

tomaszs