FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Topics & Contributions
   Tools
(Moderator: REAS)
   nanoxml
« Previous topic | Next topic »

Pages: 1 2 
   Author  Topic: nanoxml  (Read 8634 times)
toxi

WWW
nanoxml
« on: Dec 5th, 2003, 1:25pm »

just finished reading jon knudsen's J2ME book which has a nice list of lightweight xml parsers at the end. so i decided to give nanoXML a go (it's tiny: 6K) and mocked up a little example for public consumption.
 
a quick note, if you want to use nanoxml in your own sketches: the "nanoxml-lite-2.2.3.jar" file is not valid (missing manifest file), so i only got it to work with P5 after renaming it into a zip file and extracting the contents (2 classes) into a folder called "nanoxml" inside the code folder of your sketch...
 
so here's the "fake-weather" demo: http://www.toxi.co.uk/p5/nanoxmltest/  
...using this static xml file: http://www.toxi.co.uk/p5/data/test.xml
 

http://toxi.co.uk/
Martin

122417302122417302martingomez_listsmg1ph WWW Email
Re: nanoxml
« Reply #1 on: Dec 5th, 2003, 2:16pm »

hi toxi. this is a fantastic exploration. perhaps you can also implement one that reads the world's weather data for a day or some other info encoded in xml. afterwhich, save the output into a pdf file. would have done it myself if i wasn't too busy. cheers!
 
toxi

WWW
Re: nanoxml
« Reply #2 on: Dec 5th, 2003, 2:27pm »

well yes, that could be ++interesting - but i really only needed xml for something else in P5 and this was more a proof of concept thingy. as for a global weather data source, the BBC weather site would probably be a good start though...
 

http://toxi.co.uk/
TomC

WWW
Re: nanoxml
« Reply #3 on: Aug 25th, 2004, 4:50pm »

on Dec 5th, 2003, 1:25pm, toxi wrote:

 
a quick note, if you want to use nanoxml in your own sketches: the "nanoxml-lite-2.2.3.jar" file is not valid (missing manifest file), so i only got it to work with P5 after renaming it into a zip file and extracting the contents (2 classes) into a folder called "nanoxml" inside the code folder of your sketch...
 

 
As an alternative to this, you can specify the package whenever you refer to an XMLElement, e.g.
 
Code:

 
// declare a new XMLElement:
nanoxml.XMLElement xml = new nanoxml.XMLElement();
 
// a function which returns some XML
nanoxml.XMLElement getXML() {
  return xml;
}
 

 
But Toxi's method makes for neater code
 
Incidentally, I am currently trying out Java 1.5.0, and my own XML code is broken with the new plug-in (only other noticable difference is a whizzy start-up screen).  More compatibility problems!
 
toxi

WWW
Re: nanoxml
« Reply #4 on: Sep 28th, 2004, 8:46pm »

i just wrote a little extension to nanoxml's XMLElement class to select childnodes in an XPATH style manner.
 
take the following XML tree as an example:
 
Code:
<root>
  <aaa>
    <bbb>hello!</bbb>
    <bbb>world</bbb>
  <aaa>
  <bbb>welcome earthling!</bbb>
</root>

 
now in order to get to a nested <bbb> tag's content you'd have to write:
 
Code:
XMLElement xmldoc; // parsed somewhere else
XMLElement aaa=(XMLElement)(xmldoc.getChildren().elementAt(0));
XMLElement bbb=(XMLElement)(aaa.getChildren().elementAt(0));
println(bbb.getContent());

 
with more nested tree structures the code to access deep nodes will become increasingly akward and prone to errors.
 
the new method lets you directly access a defined set of nodes which match the specified tree path, like this:
 
Code:
// get all <bbb> tags inside <aaa>
Vector bbbVector=xmldoc.getChildrenForPath("aaa/bbb");
// turn into an iterator
Enumeration bbbEnum=bbbVector.elements();
while(bbbEnum.hasMoreElements()) {
  XMLElement currBBB=(XMLElement)bbbEnum.nextElement();
  println(currBBB.getContent());
}

 
the above example will return both <bbb> childnodes of the <aaa> node, but not the <bbb> node which is a sibling of <aaa>...
 
also note, this is by no means a complete XPATH parser, but even this barebones syntax already makes working with XML in Processing a lot easier...
 
now simply download the nanoxml source code and add the code below to the existing XMLElement.java:
 
Code:
/**
*
* @param path XPath style string to select childnodes at specified hierarchy
* @return Vector containing all matched childnodes
*/
public Vector getChildrenForPath(String path) {
  Vector selection = new Vector();
  StringTokenizer st = new StringTokenizer(path, "/");
  String currPath = st.nextToken();
  String subpath = st.hasMoreTokens() ? path.substring(currPath.length() + 1) : "";
  if (this.countChildren() > 0) {
    Enumeration nodeChildren = this.enumerateChildren();
    while (nodeChildren.hasMoreElements()) {
 XMLElement child = (XMLElement)nodeChildren.nextElement();
 if (child.getName().equals(currPath)) {
   if (subpath.length()>0) {
     Enumeration subselection = child.getChildrenForPath(subpath).elements();
     while (subselection.hasMoreElements())
     selection.add(subselection.nextElement());
   }
   else
   selection.add(child);
 }
    }
  }
  return selection;
}
 

http://toxi.co.uk/
eskimoblood

222550793222550793 WWW
Re: nanoxml
« Reply #5 on: Oct 25th, 2004, 5:23pm »

I try do use the parser. In processing it works fine but when i create a applet the applet crashed in the Browser.
 
TomC

WWW
Re: nanoxml
« Reply #6 on: Oct 25th, 2004, 9:06pm »

I have this problem with the new Sun java 1.5 - is that what you're using?
 
I'm going to try modifying the nanoxml source and see if that helps - it looks like there are some naming collisions with the newest java API and nanoxml.
« Last Edit: Oct 25th, 2004, 9:07pm by TomC »  
eskimoblood

222550793222550793 WWW
Re: nanoxml
« Reply #7 on: Oct 25th, 2004, 10:49pm »

No I use the following:
Java(TM) Plug-in: Version 1.4.1_07
 
eskimoblood

222550793222550793 WWW
Re: nanoxml
« Reply #8 on: Oct 25th, 2004, 11:22pm »

I figured out that is a problem to acces my extern xml file (java.security.AccessControlException: access denied (java.net.SocketPermission www.eskimoblood.de resolve)). If the xml file is in the data folder everything works fine.
 
katapulp


Re: nanoxml
« Reply #9 on: Nov 14th, 2004, 3:35pm »

I tried to run the "fake-weather demo" with the source code but it doesn't work. I put nanoXML lite (extracted in a directory like toxi wrote in his quick note) in the sketch directory, and i can't run the program.  
 
Error: "C:/processing-0068/lib/build/Temporary_8432_9911.java:8:1:8:10: Semantic Error: Type XMLElement was not found.C:/processing-0068/lib/build/Temporary_8432_9911.java:14:13:14:22:  Semantic Error: A candidate for type "XMLElement" was found, but it is invalid and needs to be fixed before this type will successfully compile.C:/processing-0068/lib/build/Temporary_8432_9911.java:47:5:47:14 : Semantic Error: A candidate for type "XMLElement" was found, but it is invalid and needs to be fixed before this type will successfully compile.C:/processing-0068/lib/build/Temporary_8432_9911.java:47:22:47:3 1: Semantic Error: A candidate for type "XMLElement" was found, but it is invalid and needs to be fixed before this type will successfully compile."
 
Any idea?
 
TomC

WWW
Re: nanoxml
« Reply #10 on: Nov 14th, 2004, 9:53pm »

What version of Java do you have?
 
I think nanoxml has problems with the latest Java runtime (1.5).  This is because some of the nanoxml class names are now used by the Java libraries.  I seem to remember that it works if you use the fully-qualified class name (namoxml.XMLElement) in your code.
 
I've got a version which works, and when I work out what to do with the licensing issues, I'll post it here.
 
Until now, my advice is to install Java 1.4.2 (at least as your browser plug-in) unless you absolutely must have things that only Java 1.5 provides.
 
katapulp


Re: nanoxml
« Reply #11 on: Nov 15th, 2004, 6:00pm »

I have java 1.4.2_06 (build 03)... It seems processing has a problem to find "XMLElement" and i don't know why, i just c/p the source code and put nanoxml-lite in the sketch directory...
 
mattgilbert

tangramkid WWW Email
Re: nanoxml
« Reply #12 on: Nov 18th, 2004, 6:47am »

Maybe it should be in your project's "code" folder? Is that where you have it?
 
i don't really know, i haven't tried to use nanoxml.
 
Matt
 
 
fjen

WWW
Re: nanoxml
« Reply #13 on: Nov 18th, 2004, 1:41pm »

i have the .classes in the code folder and it works fine. ..
 
sketch folder
+ sketch.pde
+ code
    + XMLElement.class
    + XMLException.class
+ data
    + blah.gif
 
does this work for you?
« Last Edit: Nov 18th, 2004, 1:41pm by fjen »  
katapulp


Re: nanoxml
« Reply #14 on: Nov 18th, 2004, 2:08pm »

on Nov 18th, 2004, 1:41pm, fjen wrote:

sketch folder
+ sketch.pde
+ code
    + XMLElement.class
    + XMLException.class
+ data
    + blah.gif

 
I doesn't work with the fake weather script, still the same error. I don't understand, i must have a problem with the 2 .class files...  
 
Could you please put a simple sketch online
 
Pages: 1 2 

« Previous topic | Next topic »