public int numattrs = 0;
public String[] attrs = null;
public String uri = null;
- private int delta = 0;
+ private int delta = 0;
public Node() { }
public Node(Node n) { copyFrom(n); }
}
}
+ public static class Join extends Node.Stream {
+ final Node.Stream s1, s2;
+ boolean s1Done = false;
+ public Join(Node.Stream s1, Node.Stream s2) { this.s1=s1; this.s2=s2; }
+ protected boolean _read(Node n) {
+ if (!s1Done) return s2._read(n);
+ boolean ret = s1._read(n);
+ if (ret) return true;
+ s1Done = true;
+ return s2._read(n);
+ }
+ }
+
public static class FromXML extends Node.Stream {
private final XML.Stream xml;
private XML.Elem parent = null;
protected boolean _read(Node n) { try {
Object ret = xml.next();
if (ret == null) return false;
- if (ret instanceof String) {
- n.cdata = (String)ret;
+ if (ret instanceof XML.Text) {
+ n.cdata = ((XML.Text)ret).t;
n.delta = xml.getDepth() - currentdelta;
currentdelta = xml.getDepth();
return true;
} catch (Exception e) { throw new RuntimeException(e); } }
}
- public void toXML(Writer writer) throws IOException { Node n = new Node(); if (read(n)) toXML(writer, n); }
+ public void toXML(Writer writer) throws IOException {
+ Node n = new Node();
+ do { if (!read(n)) n = null; } while (n!=null && n.cdata != null);
+ toXML(writer, n);
+ }
private Node toXML(Writer w, Node n) throws IOException {
final String name = n.name;
if (n.cdata != null) {
w.write("/>");
} else {
w.write(">");
- while(n != null && n.delta > 0) n = toXML(w, n);
+ while(n != null && n.delta > 0) { n = toXML(w, n); }
w.write("</");
w.write(name);
w.write(">");