protected Node cloneAndReplaceNamespace(Node node, String oldNS, String newNS) { Node answer = node.copy(); return replaceNamespace(answer, oldNS, newNS); }
/** Write all children of a node */ public void writeChildNodes (NodeWithChildren node) throws IOException { for (Node n: node.getNodes ()) n.toXML (this); }
public NodeWithChildren copy (Node orig) { NodeWithChildren other = (NodeWithChildren)orig; if (other.nodes != null) { for (Node n: other.nodes) { Node copy = n.createClone (); copy.copy (n); addNode (copy); } } return this; }
public DocTypeAttributeList toXML (XMLWriter writer) throws IOException { writer.write (this, "<!ATTLIST"); if (!Character.isWhitespace (elementName.charAt (0))) writer.write (this, " "); writer.write (this, elementName); boolean needsWhitespace = true; if (Character.isWhitespace (elementName.charAt (elementName.length () - 1))) needsWhitespace = false; if (needsWhitespace && !nodes.isEmpty ()) { Node n = nodes.get (0); if (n.getType () == Type.DTD_WHITESPACE) needsWhitespace = false; } if (needsWhitespace) writer.write (this, " "); for (Node n: nodes) n.toXML (writer); writer.write (this, ">"); return this; }
public static boolean isElement (Node n) { return n == null ? false : isElementType (n.getType ()); }
public static boolean isAttribute (Node n) { return n == null ? false : isAttributeType (n.getType ()); }
public void writeAttributes (Element e) throws IOException { for (Node n: e.getAttributeMap ().values ()) n.toXML (this); }
protected Node cloneAndReplaceNamespace(Node node, String oldNS, String newNS) { Node answer = node.copy(); return replaceNamespace(answer, oldNS, newNS); }
public static boolean isText (Node n) { return n == null ? false : isTextType (n.getType ()); }
@Override public DocType toXML (XMLWriter writer) throws IOException { super.toXML (writer); for (Node n: nodes) n.toXML (writer); return this; }
public static String nodeWithNamespacesToText(Node parseNode, Element namespacesNode) throws IOException { // we need to add any namespace prefixes defined in the root directory Node copy = parseNode.copy(); if (copy instanceof Element && parseNode instanceof Element) { moveCommentsIntoDescriptionElements((Element) copy, (Element) parseNode); addParentNamespaces((Element) copy, namespacesNode.getParent()); } return xmlToText(copy); }
public static String xmlToText(Node node) throws IOException { StringWriter buffer = new StringWriter(); XMLWriter writer = new XMLWriter(buffer); node.toXML(writer); writer.close(); return buffer.toString(); }
public static String nodeWithNamespacesToText(Node parseNode, Element namespacesNode) throws IOException { // we need to add any namespace prefixes defined in the root directory Node copy = parseNode.copy(); if (copy instanceof Element && parseNode instanceof Element) { moveCommentsIntoDescriptionElements((Element) copy, (Element) parseNode); addParentNamespaces((Element) copy, namespacesNode.getParent()); } return xmlToText(copy); }
public String getText () { if (!hasNodes ()) return ""; StringBuilder buffer = new StringBuilder (); for (Node n: getNodes ()) { if (isText (n)) buffer.append (((Text)n).getText ()); else if (isElement (n)) buffer.append (((Element)n).getText ()); else if (n.getType () == Type.ENTITY) buffer.append (((Entity)n).getText ()); } return buffer.toString (); }
/** Helper method for <code>String toXML()</code> to handle the * <code>IOException</code> that <code>StringWriter</code> * will never throw. */ public static String toXML (Node n) { StringWriter buffer = new StringWriter (); XMLWriter writer = new XMLWriter (buffer); try { n.toXML (writer); } catch (IOException e) //@COBEX Note: this code will never be executed { throw new RuntimeException ("Should not happen", e); //@COBEX } return buffer.toString (); }
public static String xmlToText(Node node) throws IOException { StringWriter buffer = new StringWriter(); XMLWriter writer = new XMLWriter(buffer); node.toXML(writer); writer.close(); return buffer.toString(); }
throw new XMLParseException ("It is not allowed to have content before the XML declaration", this, xmlDeclaration); switch (node.getType ()) //@COBEX throw new XMLParseException (node.getType ()+" node is not allowed here", ((BasicNode)node).getToken ()); throw new XMLParseException (node.getType ()+" node is not allowed here", this, sibling); if (node.getType () == Type.PROCESSING_INSTRUCTION)
public DocTypeNotation toXML (XMLWriter writer) throws IOException { writer.write (this, "<!NOTATION"); if (nodes.isEmpty ()) { writer.write (this, " "); writer.write (this, name); writer.write (this, " "); writer.write (this, Character.toString (quoteChar)); writer.write (this, text); writer.write (this, Character.toString (quoteChar)); } else { // TODO Sync nodes with setters for (Node n: nodes) n.toXML (writer); } writer.write (this, ">"); return this; }