View previous topic :: View next topic |
Author |
Message |
brianhsu
Joined: 17 Jan 2007 Posts: 9 Location: Taiwan
|
Posted: Sat Sep 29, 2007 9:28 am Post subject: XML parser with CDATA data. |
|
|
I'm trying read a simple XML file using arc.xml, but it seems when XML file contain CDATA, it will crash. I didn't find ticket about this.
Is there anything wrong in my code or XML file?
sample.xml
Code: |
<book>
<list>
<author>Author 1</author>
<author>Author 2</author>
</list>
<content>
<![CDATA[
This is a test.
]]>
</content>
</book>
|
test.d
Code: |
import arc.xml.all;
void main ()
{
XmlNode xml = readDocument("sample.xml");
}
|
output:
Code: |
arc.xml.error.XmlError: (8)Tags cannot start with <! [CDATA[
This is a test.
]]>
|
|
|
Back to top |
|
|
ChristianK
Joined: 26 Sep 2006 Posts: 159 Location: Berlin, Germany
|
Posted: Sun Sep 30, 2007 8:40 am Post subject: |
|
|
You'll have to wait for Clay to be around to get a definite answer to that question, but I presume that Arc's xml module only understands a subset of xml. It's meant to parse layout xml files for Arc's gui subsystem and isn't intended as a full blown bells-and-whistles xml parser. |
|
Back to top |
|
|
clayasaurus
Joined: 21 May 2004 Posts: 857
|
Posted: Sun Sep 30, 2007 2:20 pm Post subject: |
|
|
Don't use the CDATA tag, just do this...
Code: |
<book>
<list>
<author>Author 1</author>
<author>Author 2</author>
</list>
<content>
This is a test.
</content>
</book>
|
|
|
Back to top |
|
|
Carlos
Joined: 19 Mar 2004 Posts: 396 Location: Canyon, TX
|
Posted: Sun Sep 30, 2007 3:21 pm Post subject: |
|
|
Clay, I don't know what brianhsu is doing, but you have to admit that what you said is not really a helpful solution. Either he wants to have CDATA because he thinks he will need it in the future, or (even worse) he is receiving the XML from a third party and thus can't modify how the XML is created.
I'm sorry if that was too blunt. I'll go back to finishing homework now. |
|
Back to top |
|
|
clayasaurus
Joined: 21 May 2004 Posts: 857
|
Posted: Mon Oct 01, 2007 8:02 am Post subject: |
|
|
Alright...
Currently the parser doesn't support the CDATA tag. Can you please explain to me what you need the CDATA tag for?
I looked it up, and all it seems to do is let the parser ignore the data in the CDATA tag. Could you simply use XML comments <!-- comments --> instead?
Are you using a third party XML file and trying to parse it?
Please explain more clearly why you need the CDATA tag and how you plan to use it, (edit: and I'll think about implementing it, but I need more explanation for it) thanks.
edit: Also tell me what version of Arc you are using, thanks.
~ Clay |
|
Back to top |
|
|
csauls
Joined: 27 Mar 2004 Posts: 278
|
Posted: Mon Oct 01, 2007 2:42 pm Post subject: |
|
|
The text in the CDATA section is not actually ignored, it is just left unparsed, which makes it ideal for -- for example -- embedding scripting language code, or text from a resource which cannot be reasonably trusted not to violate proper XML textual syntax, such as using the < entity rather than "<".
Put another way: the text between "<![CDATA[" and "]]>" is left as-is and otherwise treated as "just" another block of text. Its the XML string literal. _________________ Chris Nicholson-Sauls |
|
Back to top |
|
|
clayasaurus
Joined: 21 May 2004 Posts: 857
|
Posted: Mon Oct 01, 2007 3:38 pm Post subject: |
|
|
Sounds reasonable enough, here's a ticket: http://www.dsource.org/projects/arclib/ticket/94
Unless someone else writes a patch, I can not guarantee it will be taken care of soon.
Also, a question about CDATA tag.
What happens with
<xml>
Test
<![CDATA[
<weird xml text data>
]]>
</xml>
Concatenation? |
|
Back to top |
|
|
csauls
Joined: 27 Mar 2004 Posts: 278
|
Posted: Tue Oct 02, 2007 5:26 pm Post subject: |
|
|
As I recall, it'd be two separate text nodes. _________________ Chris Nicholson-Sauls |
|
Back to top |
|
|
|