PDA

View Full Version : XML Parsing Error caused by XML prologue being inside a CDATA tag


gsnedders
01-04-2005, 06:39 PM
Here is my code: <?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE snippets [
<!ELEMENT snippets (snippet*)>
<!ELEMENT snippet (use,code)>
<!ELEMENT use (PCDATA)>
<!ELEMENT code (CDATA)>
]>
<snippets>
<snippet>
<use>XML Prologue</use>
<code><?xml version="1.0" encoding="utf-8" ?></code>
</snippet>
</snippets>

when viewed in Firefox, it gives the following error: XML Parsing Error: xml processing instruction not at start of external entity

chilipie
01-04-2005, 06:47 PM
Have you tried this:

<code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;</code>

Instead of this?

<code><?xml version="1.0" encoding="utf-8" ?></code>

gsnedders
01-04-2005, 06:53 PM
I want to keep everything as it will be displayed, but shouldn't the CDATA in the doctype stop it from even being parsed?

chilipie
01-04-2005, 07:00 PM
I want to keep everything as it will be displayed, but shouldn't the CDATA in the doctype stop it from even being parsed?
I had a (quick) look at theW3C XML Spec. (http://www.w3.org/TR/REC-xml/), but to be honest, I didn't understand the majority of it. David (liorean) or Jason will probably know...

gsnedders
01-04-2005, 07:13 PM
I had a (quick) look at theW3C XML Spec. (http://www.w3.org/TR/REC-xml/), but to be honest, I didn't understand the majority of it.

Neither do I :D

chilipie
01-04-2005, 07:34 PM
Neither do I :D
When I grow up big and clever, and I'm going to try and translate all the W3C stuff into moron friendly language :p .

liorean
01-04-2005, 08:09 PM
The XML specification is made for implementors, not for manual XML document writing. (XML specifications indends to primarily be formal rules that can be used by a computer in generating, parsing, editing or otherwise handle XML, and only secondarily human usable.)

As for the element definitions in the DTD, they may have one of the following types:
- 'ALL'
- 'EMPTY'
- Mixed (Either only PCDATA content or a mix of child elements and PCDATA content)
- Children (No PCDATA, only child elements)


As for your document, you must understand that PCDATA is different from #PCDATA. Any good parser will think you mean that use elements must have a single child PCDATA element. Similarly, the parser will think that you mean that code elements must have a single child CDATA element.

In difference to SGML, XML is intended to be usable without having to have a knowledge of the DTD. This means that the DTD can't be allowed to change the parsing model. Thus, you always need to use explicit CDATA sections in XML documents. CDATA sections may be present in any of the mixed content models. <![CDATA[
... your CDATA content here...
]]>

gsnedders
01-04-2005, 08:16 PM
Ahh... That clears it up vastly, thanks.