spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / xml / column36

Xparse-J Update 1.1

Sr. Web Developer
mediabistro.com
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume
Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?


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 (i < a.length()) {
      n = findChildElement(n, (String)a.elementAt(i), occur[i]);
      if (n == null) return null;
      i++;
    }
    return n;
  }

The 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

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business

URL: http://www.webreference.com/xml/column36/2.html
Created: Aug 01, 2001
Revised: Aug 01, 2001