FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

XML parser with CDATA data.

 
Post new topic   Reply to topic     Forum Index -> ArcLib
View previous topic :: View next topic  
Author Message
brianhsu



Joined: 17 Jan 2007
Posts: 9
Location: Taiwan

PostPosted: Sat Sep 29, 2007 9:28 am    Post subject: XML parser with CDATA data. Reply with quote

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
View user's profile Send private message
ChristianK



Joined: 26 Sep 2006
Posts: 159
Location: Berlin, Germany

PostPosted: Sun Sep 30, 2007 8:40 am    Post subject: Reply with quote

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
View user's profile Send private message
clayasaurus



Joined: 21 May 2004
Posts: 857

PostPosted: Sun Sep 30, 2007 2:20 pm    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
Carlos



Joined: 19 Mar 2004
Posts: 396
Location: Canyon, TX

PostPosted: Sun Sep 30, 2007 3:21 pm    Post subject: Reply with quote

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
View user's profile Send private message Yahoo Messenger MSN Messenger
clayasaurus



Joined: 21 May 2004
Posts: 857

PostPosted: Mon Oct 01, 2007 8:02 am    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
csauls



Joined: 27 Mar 2004
Posts: 278

PostPosted: Mon Oct 01, 2007 2:42 pm    Post subject: Reply with quote

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 &lt; 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
View user's profile Send private message AIM Address Yahoo Messenger
clayasaurus



Joined: 21 May 2004
Posts: 857

PostPosted: Mon Oct 01, 2007 3:38 pm    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
csauls



Joined: 27 Mar 2004
Posts: 278

PostPosted: Tue Oct 02, 2007 5:26 pm    Post subject: Reply with quote

As I recall, it'd be two separate text nodes.
_________________
Chris Nicholson-Sauls
Back to top
View user's profile Send private message AIM Address Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> ArcLib All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group