Package org.citrusframework.util
Class XMLUtils
java.lang.Object
org.citrusframework.util.XMLUtils
Class providing several utility methods for XML processing.
- Since:
- 2006
- Author:
- Jan Szczepanski, Christoph Deppisch
-
Method Summary
Modifier and TypeMethodDescriptionstatic LSInputCreates LSInput from dom implementation.static LSOutputCreates LSOutput from dom implementation.static LSParserCreates basic parser instance.static LSSerializerCreates basic serializer instance.static NodefindNodeByName(Document doc, String pathExpression) Searches for a node within a DOM document with a given node path expression.static StringgetNodesPathName(Node node) Returns the path expression for a given node.static CharsetgetTargetCharset(Document doc) Try to find encoding for document node.static voidinitialize(XmlConfigurer xmlConfigurer) Initializes XML utilities with custom configurer.lookupNamespaces(Node referenceNode) Look up namespace attribute declarations in the specified node and store them in a binding map, where the key is the namespace prefix and the value is the namespace uri.static StringomitXmlDeclaration(String xml) Removes leading XML declaration from xml if present.static DocumentparseMessagePayload(String messagePayload) Parse message payload with DOM implementation.static StringprettyPrint(String xml) Pretty prints a XML string.static StringSerializes a DOM documentstatic voidstripWhitespaceNodes(Node element) Removes text nodes that are only containing whitespace characters inside a DOM tree.
-
Method Details
-
initialize
Initializes XML utilities with custom configurer.- Parameters:
xmlConfigurer-
-
createLSParser
Creates basic parser instance.- Returns:
-
createLSSerializer
Creates basic serializer instance.- Returns:
-
createLSInput
Creates LSInput from dom implementation.- Returns:
-
createLSOutput
Creates LSOutput from dom implementation.- Returns:
-
findNodeByName
Searches for a node within a DOM document with a given node path expression. Elements are separated by '.' characters. Example: Foo.Bar.Poo- Parameters:
doc- DOM Document to search for a node.pathExpression- dot separated path expression- Returns:
- Node element found in the DOM document.
-
stripWhitespaceNodes
Removes text nodes that are only containing whitespace characters inside a DOM tree.- Parameters:
element- the root node to normalize.
-
getNodesPathName
Returns the path expression for a given node. Path expressions look like: Foo.Bar.Poo where elements are separated with a dot character.- Parameters:
node- in DOM tree.- Returns:
- the path expression representing the node in DOM tree.
-
serialize
Serializes a DOM document- Parameters:
doc-- Returns:
- serialized XML string
- Throws:
org.citrusframework.exceptions.CitrusRuntimeException
-
prettyPrint
Pretty prints a XML string.- Parameters:
xml-- Returns:
- pretty printed XML string
- Throws:
org.citrusframework.exceptions.CitrusRuntimeException
-
lookupNamespaces
Look up namespace attribute declarations in the specified node and store them in a binding map, where the key is the namespace prefix and the value is the namespace uri.- Parameters:
referenceNode- XML node to search for namespace declarations.- Returns:
- map containing namespace prefix - namespace url pairs.
-
parseMessagePayload
Parse message payload with DOM implementation.- Parameters:
messagePayload-- Returns:
- DOM document.
- Throws:
org.citrusframework.exceptions.CitrusRuntimeException
-
getTargetCharset
Try to find encoding for document node. Also supports Citrus default encoding set as System property.- Parameters:
doc-- Returns:
-
omitXmlDeclaration
Removes leading XML declaration from xml if present.- Parameters:
xml-- Returns:
-