X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2Futil%2FXML.java;h=8470e8dcf15293baffcbbbf5c1f336444876ae7f;hb=d821a37fdc4f7c3fbe54216202108994a5b5bd20;hp=64940c21e49bd416702912fdf0a2b1f4d2cfe2a8;hpb=4d09ad347d2133085802a57024bb94ba6bdb9087;p=org.ibex.util.git diff --git a/src/org/ibex/util/XML.java b/src/org/ibex/util/XML.java index 64940c2..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; } @@ -973,7 +990,7 @@ public abstract class XML 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;