Package org.htmlunit.util
Class XmlUtils
- java.lang.Object
-
- org.htmlunit.util.XmlUtils
-
public final class XmlUtils extends java.lang.ObjectINTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Provides facility method to work with XML responses.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classXmlUtils.TrackBlankContentAndSkipLeadingWhitespaceReaderHelper for memory and performance optimization.
-
Field Summary
Fields Modifier and Type Field Description private static org.xml.sax.ErrorHandlerDISCARD_MESSAGES_HANDLERprivate static org.apache.commons.logging.LogLOG
-
Constructor Summary
Constructors Modifier Constructor Description privateXmlUtils()Utility class, hide constructor.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidappendChild(SgmlPage page, DomNode parent, org.w3c.dom.Node child, boolean handleXHTMLAsHTML)Recursively appends aNodechild toDomNodeparent.static voidappendChild(SgmlPage page, DomNode parent, org.w3c.dom.Node child, boolean handleXHTMLAsHTML, java.util.Map<java.lang.Integer,java.util.List<java.lang.String>> attributesOrderMap)Recursively appends aNodechild toDomNodeparent.static org.w3c.dom.DocumentbuildDocument(WebResponse webResponse)Builds a document from the content of the web response.private static voidcopy(SgmlPage page, org.w3c.dom.Node source, DomNode dest, boolean handleXHTMLAsHTML, java.util.Map<java.lang.Integer,java.util.List<java.lang.String>> attributesOrderMap)Copy all children from 'source' to 'dest', within the context of the specified page.private static DomNodecreateFrom(SgmlPage page, org.w3c.dom.Node source, boolean handleXHTMLAsHTML, java.util.Map<java.lang.Integer,java.util.List<java.lang.String>> attributesOrderMap)static java.util.Map<java.lang.Integer,java.util.List<java.lang.String>>getAttributesOrderMap(org.w3c.dom.Document document)Returns internal Xerces details about all elements in the specified document.static java.lang.StringlookupNamespaceURI(DomElement element, java.lang.String prefix)Search for the namespace URI of the given prefix, starting from the specified element.static java.lang.StringlookupPrefix(DomElement element, java.lang.String namespace)Search for the prefix associated with specified namespace URI.private static org.xml.sax.AttributesnamedNodeMapToSaxAttributes(org.w3c.dom.NamedNodeMap attributesMap, java.util.Map<java.lang.Integer,java.util.List<java.lang.String>> attributesOrderMap, org.w3c.dom.Node element)
-
-
-
Method Detail
-
buildDocument
public static org.w3c.dom.Document buildDocument(WebResponse webResponse) throws java.io.IOException, org.xml.sax.SAXException, javax.xml.parsers.ParserConfigurationException
Builds a document from the content of the web response. A warning is logged if an exception is thrown while parsing the XML content (for instance when the content is not a valid XML and can't be parsed).- Parameters:
webResponse- the response from the server- Returns:
- the parse result
- Throws:
java.io.IOException- if the page could not be createdorg.xml.sax.SAXException- if the parsing failsjavax.xml.parsers.ParserConfigurationException- if a DocumentBuilder cannot be created
-
appendChild
public static void appendChild(SgmlPage page, DomNode parent, org.w3c.dom.Node child, boolean handleXHTMLAsHTML)
Recursively appends aNodechild toDomNodeparent.- Parameters:
page- the owner page ofDomElements to be createdparent- the parent DomNodechild- the child NodehandleXHTMLAsHTML- if true elements from the XHTML namespace are handled as HTML elements instead of DOM elements
-
appendChild
public static void appendChild(SgmlPage page, DomNode parent, org.w3c.dom.Node child, boolean handleXHTMLAsHTML, java.util.Map<java.lang.Integer,java.util.List<java.lang.String>> attributesOrderMap)
Recursively appends aNodechild toDomNodeparent.- Parameters:
page- the owner page ofDomElements to be createdparent- the parent DomNodechild- the child NodehandleXHTMLAsHTML- if true elements from the XHTML namespace are handled as HTML elements instead of DOM elementsattributesOrderMap- (optional) the one returned bygetAttributesOrderMap(Document)
-
createFrom
private static DomNode createFrom(SgmlPage page, org.w3c.dom.Node source, boolean handleXHTMLAsHTML, java.util.Map<java.lang.Integer,java.util.List<java.lang.String>> attributesOrderMap)
-
namedNodeMapToSaxAttributes
private static org.xml.sax.Attributes namedNodeMapToSaxAttributes(org.w3c.dom.NamedNodeMap attributesMap, java.util.Map<java.lang.Integer,java.util.List<java.lang.String>> attributesOrderMap, org.w3c.dom.Node element)
-
copy
private static void copy(SgmlPage page, org.w3c.dom.Node source, DomNode dest, boolean handleXHTMLAsHTML, java.util.Map<java.lang.Integer,java.util.List<java.lang.String>> attributesOrderMap)
Copy all children from 'source' to 'dest', within the context of the specified page.- Parameters:
page- the page which the nodes belong tosource- the node to copy fromdest- the node to copy tohandleXHTMLAsHTML- if true elements from the XHTML namespace are handled as HTML elements instead of DOM elements
-
lookupNamespaceURI
public static java.lang.String lookupNamespaceURI(DomElement element, java.lang.String prefix)
Search for the namespace URI of the given prefix, starting from the specified element. The default namespace can be searched for by specifying "" as the prefix.- Parameters:
element- the element to start searching fromprefix- the namespace prefix- Returns:
- the namespace URI bound to the prefix; or null if there is no such namespace
-
lookupPrefix
public static java.lang.String lookupPrefix(DomElement element, java.lang.String namespace)
Search for the prefix associated with specified namespace URI.- Parameters:
element- the element to start searching fromnamespace- the namespace prefix- Returns:
- the prefix bound to the namespace URI; or null if there is no such namespace
-
getAttributesOrderMap
public static java.util.Map<java.lang.Integer,java.util.List<java.lang.String>> getAttributesOrderMap(org.w3c.dom.Document document)
Returns internal Xerces details about all elements in the specified document. The id of the returnedMapis thenodeIndexof an element, and the list is the array of ordered attributes names.- Parameters:
document- the document- Returns:
- the map of an element index with its ordered attribute names
-
-