Xparse-J Update 1.1 (2/2) - exploring XML
Xparse-J Update 1.1
Code Change
The code change of Node.find() is relatively minor:
public Node find(String path, int[] occur) { Node n = this; JSArray a = new JSArray(); a.split(path, "/"); int i = 0; while (iThe findChildElement() method is now called with every corresponding occurrence parameter in order to return the n-th Node of the respective simple path expression, i.e. child element. Be prepared to catch an IndexOutOfBounds exception if the array does not have as many elements as the path expression.
Adapting the RSSViewerApplet was quite straightforward as well:
public void load(String srcURL) throws Exception { int dim[] = {1, 1}; root = new Xparse().parse(readChannel(srcURL)); ... while (true) { n = top.find("item/title", dim); if (n == null) break; items.insertElementAt(n.getCharacters(), 2*dim[0]-2); n = top.find("item/link", dim); if (n == null) break; items.insertElementAt(new URL(n.getCharacters()), 2*dim[0]-1); ++dim[0]; } }The loop over RSS items happens in the first dimension of the occurrence array, as every item only has one title and one link. Everything else remains unchanged.
Conclusion
With this update to Node.find() Xparse-J is now a truly generic tool for parsing and manipulating XML documents. If you can live without all the hard 'n heavy W3C functionality present in the heavyweights of Xerces and xml4j, give Xparse-J a try!
Produced by Michael Claßen
URL: https://www.webreference.com/xml/column36/2.html
Created: Aug 01, 2001
Revised: Aug 01, 2001