Class XMLUtils

java.lang.Object
org.citrusframework.util.XMLUtils

public final class XMLUtils extends Object
Class providing several utility methods for XML processing.
Since:
2006
Author:
Jan Szczepanski, Christoph Deppisch
  • Method Details

    • initialize

      public static void initialize(XmlConfigurer xmlConfigurer)
      Initializes XML utilities with custom configurer.
      Parameters:
      xmlConfigurer -
    • createLSParser

      public static LSParser createLSParser()
      Creates basic parser instance.
      Returns:
    • createLSSerializer

      public static LSSerializer createLSSerializer()
      Creates basic serializer instance.
      Returns:
    • createLSInput

      public static LSInput createLSInput()
      Creates LSInput from dom implementation.
      Returns:
    • createLSOutput

      public static LSOutput createLSOutput()
      Creates LSOutput from dom implementation.
      Returns:
    • findNodeByName

      public static Node findNodeByName(Document doc, String pathExpression)
      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

      public static void stripWhitespaceNodes(Node element)
      Removes text nodes that are only containing whitespace characters inside a DOM tree.
      Parameters:
      element - the root node to normalize.
    • getNodesPathName

      public static String getNodesPathName(Node node)
      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

      public static String serialize(Document doc)
      Serializes a DOM document
      Parameters:
      doc -
      Returns:
      serialized XML string
      Throws:
      org.citrusframework.exceptions.CitrusRuntimeException
    • prettyPrint

      public static String prettyPrint(String xml)
      Pretty prints a XML string.
      Parameters:
      xml -
      Returns:
      pretty printed XML string
      Throws:
      org.citrusframework.exceptions.CitrusRuntimeException
    • lookupNamespaces

      public static Map<String,String> 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.
      Parameters:
      referenceNode - XML node to search for namespace declarations.
      Returns:
      map containing namespace prefix - namespace url pairs.
    • parseMessagePayload

      public static Document parseMessagePayload(String messagePayload)
      Parse message payload with DOM implementation.
      Parameters:
      messagePayload -
      Returns:
      DOM document.
      Throws:
      org.citrusframework.exceptions.CitrusRuntimeException
    • getTargetCharset

      public static Charset getTargetCharset(Document doc)
      Try to find encoding for document node. Also supports Citrus default encoding set as System property.
      Parameters:
      doc -
      Returns:
    • omitXmlDeclaration

      public static String omitXmlDeclaration(String xml)
      Removes leading XML declaration from xml if present.
      Parameters:
      xml -
      Returns: