We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpIntegration › is there a nice petite xml parser that you like
Page Index Toggle Pages: 1
is there a nice petite xml parser that you like? (Read 3560 times)
is there a nice petite xml parser that you like?
Apr 27th, 2005, 7:44pm
 
I am a bit of a newbie to the java scene. Is there a SMALL xml parser that people like to use with Processing...i want to bring in some xml structured data...and I just don't want to write my own. I can live with minimal functionality and I want something that will run in applet sized environemnt...surely someone has faced this before..

thanks much
-jd

Re: is there a nice petite xml parser that you lik
Reply #1 - Apr 27th, 2005, 8:05pm
 
I've used Xalan and Xerces before. I'm not sure how well they meet the "small" requirement, but they're easy to set up and use.

Re: is there a nice petite xml parser that you lik
Reply #2 - Apr 27th, 2005, 8:35pm
 
i've used nanoxml with prebeta versions of processing and it worked fine.

goto the old alpha forum (link up top)and search for 'nanoxml'
Re: is there a nice petite xml parser that you lik
Reply #3 - Apr 27th, 2005, 11:01pm
 
Thanks, nanoxml seems to work ok, though I can't seem to get it to read a file directly. No matter though as I can load it myself and parse the big string once I put it together the way nano seems to want it.
Now I can generate my visual trees....this is getting good.
-jd
Re: is there a nice petite xml parser that you lik
Reply #4 - Apr 27th, 2005, 11:22pm
 
try:

Code:

XMLElement xml = new XMLElement();
Reader reader = new InputStreamReader(openStream("eota.xml"));
try{
xml.parseFromReader(reader);
}
catch (Exception e) { e.printStackTrace(); }


where "eota.xml" is inside the "data" folder inside the sketch-folder.

F
Re: is there a nice petite xml parser that you lik
Reply #5 - Apr 29th, 2005, 2:19am
 
Thanks fjen, that last bit o code works nicely and i can now parse directly from the file.

But I now to have a more serious problem. It seems that the version of nanoxml (all?) i am using will not parse valid xml that has children inside text nodes.
That would be ok if it ignored the children of text nodes but instead it generates an exception that aborts the parse. Since I might want to parse data that has embedded xml-compliant html markup, it appears that I cannot use nanoxml. But maybe I am missing somthing (i hope). Anybody run into this problem before?

peace
jd
Re: is there a nice petite xml parser that you lik
Reply #6 - Apr 29th, 2005, 2:06pm
 
can you post a short example? i think you're misunderstanding text-nodes. it is basicly everything between two tags:

<a>
 text1
 <b>
   text2
     <c />
   text3
 </b>
 text4
</a>

F

...

Code:

<?xml version="1.0" encoding="UTF-8" ?>
<root>
<node1><[CDATA[

<?xml version="1.0" encoding="UTF-8" ?>
<root2>
<node2></node2>
<node3></node3>
<node4></node4>
</root2>

]]></node1>
</root>


everything inside <[CDATA[ ]]>  will be parsed as text/data ignoring the markups. but this trick only works once, since if you put  <[CDATA[ <![CDATA[ ]]>** ]]> it will  assume the text ends before **.

another trick i sometimes used is to encode the data in the cdata nodes.

F
Re: is there a nice petite xml parser that you lik
Reply #7 - Apr 29th, 2005, 2:13pm
 
encoding?

http://www.source-code.biz/snippets/java/2.htm

or

http://java.sun.com/j2se/1.4.2/docs/api/java/net/URLEncoder.html

F
Re: is there a nice petite xml parser that you lik
Reply #8 - Apr 29th, 2005, 10:13pm
 
It may be that I don't understand the problem. Here is a link to the offending xml. I find that various xml editors all claim that this xml is well formed and i have loaded it into xml type and parsed it in flash without a blip. WHen I load it using nano it throws a parsing exception. Perhaps the doc is not actually well formed in some way that most editors ignore.

The xml is the defeining doc for my little flash website, and the xml itself if located at
www.physicstree.net/contents/physicstree.xml

thanks for looking at this
-jd
Re: is there a nice petite xml parser that you lik
Reply #9 - Apr 30th, 2005, 5:26am
 
your xml is valid exept for it's missing the header ..

but i think it is a bug in nanoxml anyway, you should report it to them.
what i found:
the parse exception occures with any text placed inbetween nodes like this:
Code:

<a>
<b>
ok text
</b>
bad text
<c>
ok text
</c>
bad text
</a>


since you seam to just parse the html thru you could wrap that pieces that are actually text mixed with html inside CDATA tags , like:

Code:

<?xml version="1.0" encoding="UTF-8" ?>
<root><![CDATA[
<font>
ok text
</font>
ok text
<font>
ok text
</font>
ok text]]>
</root>


... but you will not be able to access the nodes inside cdata from this XMLElement (they are considered data/text). so the trick is to read whats in there and parse that thru another XMLElement ... ufff, hope that's clear enough?

best,
F
Re: is there a nice petite xml parser that you lik
Reply #10 - Apr 30th, 2005, 1:02pm
 
the issue with nanoxml lite is not a bug, but the lack of support for mixed content, i.e. text nodes which contain further markup.

from the website http://nanoxml.sf.net/
Quote:
NanoXML/Lite
An extremely small (6KB) XML parser which is the successor of NanoXML 1. It only provides a limited functionality: no mixed content and the DTD is ignored.


IIRC mixed content is only valid in XML when a suitable DTD is given, without it text elements must not contain any tags (or have them escaped).
Re: is there a nice petite xml parser that you lik
Reply #11 - Apr 30th, 2005, 9:26pm
 
I did read that about nanoxml lite. Apparently it is also true for the non-lite nanoxml as well though I will double check it. It appears that I will be looking for another parsing solution or to move the parsing functionality entirely out of this code. Thanks   toxi and fjen for looking at it!
-jd
Re: is there a nice petite xml parser that you lik
Reply #12 - May 9th, 2005, 10:31am
 
Hi John

You could try my proHtml library it is also able to build and parse XML. You can parse a XML Document into a list or a tree structure. I made a sketch using the XML output from Flickr and it worked fine.

tex
Page Index Toggle Pages: 1