Tools Update: RSSApplet and Xparse-J (3/4) - exploring XML | WebReference

Tools Update: RSSApplet and Xparse-J (3/4) - exploring XML

Tools Update: RSSApplet and Xparse-J

Xparse-J

One building block for the RSSApplet is an XML parser to read in the RSS file. The first versions of RSSApplet used Aelfred, a fairly small Java XML parser. In an effort to shrink the applet size even further I translated Xparse from JavaScript to Java, and implemented JSArray to mimic JavaScript arrays in Java. The result is now released separately as Xparse-J, the initial version 1.0 is a literal translation of Xparse 0.91, plus some Java-specific adaptations.

The creator of Xparse, Jeremie, states that Xparse is a fully-compliant well-formed XML parser, with the exception of full error reporting, internal document type definitions, and related DTD functionality. I tend to think there is a bit more missing in terms of resolving external entities and especially handling Non-Unicode character sets.

A code walk-through of Xparse-j

Xparse-j consists of three classes in the package com.exploringxml.xml, the main parser class Xparse, the parsed document in Nodes, and the utility class JSArray.
public class Xparse {
  private String substring(String s, int start, int length) {
    if (s.length() > start + length)
      return s.substring(start, length);
    else
      return s.substring(start);
  }
  ...

The substring function bridges one important difference between Java and JavaScript: While JavaScript always returns the rest of the string if the substring length exceeds the string length, Java throws an IndexOutOfBoundsException. The above code snippet implements the JavaScript behavior in Java. I included this in Xparse because subclassing java.lang.String is not possible, and wrapping String in a new class JSString duplicates a lot of code since all the built-in string functions need to be delegated into and out of String. Also the syntax only slightly changes from str.substring(start, length) to substring(str, start, length).

We conclude with XPath.

https://www.internet.com

Produced by Michael Claßen
All Rights Reserved. Legal Notices.

URL: https://www.webreference.com/xml/column26/3.html
Created: Dec 15, 2000
Revised: Dec 15, 2000