java.lang.Object
de.hybris.platform.integrationservices.util.XmlObject

public final class XmlObject extends Object
A helper object for evaluating Json content by utilizing XPath expressions.
  • Method Details

    • createFrom

      public static XmlObject createFrom(InputStream in)
      Parses XML content from the input stream and creates new XML object
      Parameters:
      in - an input stream containing XML
      Returns:
      an object for evaluating structure of the parsed content
      Throws:
      IllegalArgumentException - if the input stream fails to read or contains a malformed XML
    • createFrom

      public static XmlObject createFrom(String xml)
      Parses XML content and creates new XML object
      Parameters:
      xml - an XML content to parse
      Returns:
      an object for evaluating structure of the parsed content
      Throws:
      IllegalArgumentException - if the content contains a malformed XML
    • get

      public String get(String path)
      Looks up a value in the parsed XML
      Parameters:
      path - a XML path, e.g. //product/code, pointing to the element whose value needs to be retrieved.
      Returns:
      value of the element matching the path location.
    • transform

      public <T> List<T> transform(String path, Function<Node,T> f)
      Retrieves all nodes matching the path and transforms them using the function.
      Parameters:
      path - an XML path, e.g. //product/code, pointing to the nodes to transform.
      f - a function to apply to each node matching the path.
      Returns:
      a list containing results of applying the function to the matching nodes in the order they were selected from the XML content; or an empty list, if there are no matching nodes found.
    • count

      public int count(String path)
      Counts the number of nodes matching the path
      Parameters:
      path - a XML path, e.g. //product/code, pointing to the elements to be counted.
      Returns:
      number of the elements matching the path location.
    • exists

      public boolean exists(String path)
      Checks whether the specified xpath exists in this XML object.
      Parameters:
      path - an xPath, e.g. //product/code to be verified
      Returns:
      true, if the specified path exists in this XML object;
    • toString

      public String toString()
      Overrides:
      toString in class Object