From: adam Date: Fri, 18 Feb 2005 10:50:45 +0000 (+0000) Subject: fixed David's awful breakage to the pull-parser X-Git-Url: http://git.megacz.com/?p=org.ibex.util.git;a=commitdiff_plain;h=a60de8e7eb83e6cd67cab1283a995511652d188e fixed David's awful breakage to the pull-parser darcs-hash:20050218105045-5007d-59a476dd3d72f625c53620d402fc613ce547adf5.gz --- diff --git a/src/org/ibex/util/XML.java b/src/org/ibex/util/XML.java index 169b262..8470e8d 100644 --- a/src/org/ibex/util/XML.java +++ b/src/org/ibex/util/XML.java @@ -164,7 +164,7 @@ public abstract class XML } // move through meaningless data - if (current != null) readChars(false); + //if (current != null) readChars(false); if (buf[off] == '<') { // proecess and return a tag @@ -936,20 +936,37 @@ public abstract class XML 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; } } } @@ -960,9 +977,9 @@ public abstract class XML // 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; }