}
// move through meaningless data
- if (current != null) readChars(false);
+ //if (current != null) readChars(false);
if (buf[off] == '<') {
// proecess and return a tag
/** Creates a new XML.Stream. Default initial buffer size is used. */
public Stream() { this(null, BUFFER_SIZE); }
+ public Stream(Reader in) { this(in, BUFFER_SIZE); }
+
/** Creates a new XML.Stram with a sepcified character source and
* initial buffer size. */
public Stream(Reader in, int bSize) {
private final class SXML extends XML {
private StringBuffer chars = new StringBuffer();
private Tree.Element element = null;
+ private Queue queue = new Queue(10);
+ int depth0 = 0;
private SXML(int b) { super(b, false); }
- public void startElement(Tree.Element e) { depth++; element = e; }
- public void endElement(Tree.Element e) { depth--; element = e; }
+ public void startElement(Tree.Element e) {
+ if (chars.length() > 0) {
+ queue.append(chars.toString());
+ queue.append(new Integer(depth0));
+ chars.setLength(0);
+ }
+ queue.append(e);
+ queue.append(new Integer(depth0));
+ depth0++;
+ }
+ public void endElement(Tree.Element e) {
+ if (chars.length() > 0) {
+ queue.append(chars.toString());
+ queue.append(new Integer(depth0));
+ chars.setLength(0);
+ }
+ depth0--;
+ }
+ public void whitespace(char[] ch, int s, int l) { characters(ch, s, l); }
public void characters(char[] ch, int s, int l) { chars.append(ch, s, l); }
private Tree.Leaf next() throws IOException, Exn {
- if (!parseNext()) return null;
- if (element != null) {
- Tree.Element e = element; element = null; return e;
- } else if (chars.length() > 0) {
- Tree.Leaf l = new Text(current(), chars.toString());
- chars = new StringBuffer(); return l;
- }
- return null;
+ while (queue.size() == 0)
+ if (!parseNext()) return null;
+ Object o = queue.remove();
+ depth = ((Integer)queue.remove()).intValue();
+ if (o instanceof String) return new Text(current(), (String)o);
+ else return (Tree.Leaf)o;
}
}
}
// Support Classes ////////////////////////////////////////////////////////
/** Represents a block of text in an XML.Document model. */
- private static final class Text implements Tree.Leaf, Serializable {
+ public static final class Text implements Tree.Leaf, Serializable {
private Tree.Node p;
- private String t;
+ public String t;
Text() {}
Text(Tree.Node p, String t) { this.t = t; this.p = p; }
public void out(OutputStream out) { throw new UnsupportedOperationException(); }
}
- private static final class Elem
+ public static final class Elem
implements Tree.Element, Tree.Attributes, Tree.Prefixes, Serializable {
private String uri = null;
private String localName = null;