Package org.htmlunit.util
Class XmlUtils
java.lang.Object
org.htmlunit.util.XmlUtils
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Provides facility method to work with XML responses.
Provides facility method to work with XML responses.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
Helper for memory and performance optimization. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final ErrorHandler
private static final org.apache.commons.logging.Log
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
appendChild
(SgmlPage page, DomNode parent, Node child, boolean handleXHTMLAsHTML) static void
appendChild
(SgmlPage page, DomNode parent, Node child, boolean handleXHTMLAsHTML, Map<Integer, List<String>> attributesOrderMap) static Document
buildDocument
(WebResponse webResponse) Builds a document from the content of the web response.private static void
copy
(SgmlPage page, Node source, DomNode dest, boolean handleXHTMLAsHTML, Map<Integer, List<String>> attributesOrderMap) Copy all children from 'source' to 'dest', within the context of the specified page.private static DomNode
createFrom
(SgmlPage page, Node source, boolean handleXHTMLAsHTML, Map<Integer, List<String>> attributesOrderMap) getAttributesOrderMap
(Document document) Returns internal Xerces details about all elements in the specified document.static String
lookupNamespaceURI
(DomElement element, String prefix) Search for the namespace URI of the given prefix, starting from the specified element.static String
lookupPrefix
(DomElement element, String namespace) Search for the prefix associated with specified namespace URI.private static Attributes
namedNodeMapToSaxAttributes
(NamedNodeMap attributesMap, Map<Integer, List<String>> attributesOrderMap, Node element)
-
Field Details
-
LOG
private static final org.apache.commons.logging.Log LOG -
DISCARD_MESSAGES_HANDLER
-
-
Constructor Details
-
XmlUtils
private XmlUtils()Utility class, hide constructor.
-
-
Method Details
-
buildDocument
public static Document buildDocument(WebResponse webResponse) throws IOException, SAXException, 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:
IOException
- if the page could not be createdSAXException
- if the parsing failsParserConfigurationException
- if a DocumentBuilder cannot be created
-
appendChild
public static void appendChild(SgmlPage page, DomNode parent, Node child, boolean handleXHTMLAsHTML) - Parameters:
page
- the owner page ofDomElement
s 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, Node child, boolean handleXHTMLAsHTML, Map<Integer, List<String>> attributesOrderMap) - Parameters:
page
- the owner page ofDomElement
s 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
-
namedNodeMapToSaxAttributes
private static Attributes namedNodeMapToSaxAttributes(NamedNodeMap attributesMap, Map<Integer, List<String>> attributesOrderMap, Node element) -
copy
private static void copy(SgmlPage page, Node source, DomNode dest, boolean handleXHTMLAsHTML, Map<Integer, List<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
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
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
Returns internal Xerces details about all elements in the specified document. The id of the returnedMap
is thenodeIndex
of 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
-