public String getPath () { if (path == null) { NodeWithChildren n = currentNode (); if (n.getType () == Type.DOCUMENT) path = "/"; else path = ((Element)n).getChildPath (); } return path; }
/** Convenience method to parse a file into XML. * @throws IOException */ public static Document parse (File file) throws IOException { XMLIOSource source = new XMLIOSource (file); XMLParser parser = new XMLParser (); return parser.parse (source); } }
/** * Check that the next character is {@code expected} and skip it */ protected void expect (char expected) { if (pos >= source.length () || source.charAt (pos) != expected) { throw new XMLParseException ("Expected '"+expected+"'"+lookAheadForErrorMessage ("but found", pos, 20), source, pos); } pos ++; }
protected XMLDeclaration createXMLDeclaration () { if (xmlDeclaration == null) { addNode (0, new XMLDeclaration ("1.0")); addNode (1, new Text ("\n")); } return xmlDeclaration; }
protected char nextChar (String errorMessage) { if (pos >= source.length ()) throw new XMLParseException (errorMessage, source, pos); return source.charAt (pos ++); }
public void remove() { if( null == getParent() ) { return; } getParent().removeNode( this ); } }
public boolean hasSingleTextChild (Element e) { if (e.nodeCount () != 1) return false; Node node = e.getNode (0); if (!XMLUtils.isText (node)) return false; Text t = (Text)node; return !t.isWhitespace (); }
public XMLParseException setToken (Token token) { this.token = token; if (token != null) { setSource (token.getSource (), token.getStartOffset ()); } return this; }
/** Return the text with all special characters (like line feed, new line, null bytes, characters * in the unicode range) escaped. * * <p>The result of this method can use used directly in a Java String. * * @return the text (without quotes) or <code>null</code> if there is no source */ public String getEscapedText () { return TextUtils.escapeJavaString (getText ()); }
public static XMLDeclaration parseXMLDeclaration (ProcessingInstruction pi) { XMLDeclaration decl = new XMLDeclaration ("1.0"); decl.parseXMLDeclaration (pi.getValue ()); return decl; }