Class XmlHelper

java.lang.Object
core.apiCore.helpers.XmlHelper

public class XmlHelper
extends Object
  • Constructor Details

    • XmlHelper

      public XmlHelper()
  • Method Details

    • convertDocumentToString

      public static String convertDocumentToString​(Document doc)
      Convert a contents of a Document to a String
      Parameters:
      doc -
      Returns:
      String
    • convertXmlStringToDocument

      public static Document convertXmlStringToDocument​(String xmlStr)
      Convert a String in XML format to a Document
      Parameters:
      xmlStr -
      Returns:
      Document
    • convertXmlFileToString

      public static String convertXmlFileToString​(Path filePath)
      Convert contents of an XML file to a string
      Parameters:
      filePath -
      Returns:
      String
    • readFile

      public static Document readFile​(String inputFilePath)
      Read a XML file And get a Document retrying And catching interruptions from other threads.
      Parameters:
      inputFilePath -
      Returns:
      Document
    • getNodeValue

      public static String getNodeValue​(String xpathString, String xmlString)
      Get text value of the node specified by xpath
      Parameters:
      xpathString -
      xmlString -
      Returns:
      String
    • getNodeList

      public static NodeList getNodeList​(String xpathString, String xmlString)
      Get text value of the node specified by xpath
      Parameters:
      xpathString -
      xmlString -
      Returns:
      String
    • getXpathValueFromJson

      public static String getXpathValueFromJson​(String json, String xpath)
      converts json string to xml and gets xpath value from it
      Parameters:
      json -
      xpath -
      Returns:
      result list as string separated by ","
    • getXpathFromXml

      public static String getXpathFromXml​(String xml, String xpath)
      get xpath value form xml string test out xpath values at: https://www.freeformatter.com/xpath-tester.html#ad-output
      Parameters:
      xml -
      xpath -
      Returns:
      result list as string separated by ","
    • jsonToXml

      public static String jsonToXml​(String json)
      convert json string to xml string
      Parameters:
      json -
      Returns:
    • getRequestBodyFromXmlTemplate

      public static String getRequestBodyFromXmlTemplate​(ServiceObject serviceObject)
      if request body is empty, return xml template string if request body contains xml tag, replace tag with value eg. "soi:EquipmentID:1:equip_<@_TIME_17>"
      Parameters:
      serviceObject -
      Returns:
    • replaceTagValue

      public static String replaceTagValue​(String xml, String tag, String value, int position)
      replace tag value in xml string at index
      Parameters:
      position - : starts at 1
      tag -
      value -
      Returns:
    • replaceTagValue

      public static String replaceTagValue​(String xml, String tag, String value)
      replace tag value in xml for all occurrences
      Parameters:
      xml -
      tag -
      value -
      Returns:
    • replaceGroup

      public static String replaceGroup​(String regex, String source, int groupToReplace, int groupOccurrence, String replacement)
      generic replace value using regex using index
      Parameters:
      regex -
      source -
      groupToReplace -
      groupOccurrence -
      replacement -
      Returns:
    • replaceRequestTagValues

      public static String replaceRequestTagValues​(String requestbody, String xmlString)
      replaces request header tag values eg. "soi:EquipmentID:1:<@_TIME_16>" tag: soi:EquipmentID, position: 1, value: <@_TIME_16>
      Parameters:
      serviceObject -
      Returns:
    • getXmlTagValue

      public static String getXmlTagValue​(String value, String tag)
      get first matching tag value
      Parameters:
      requestBody -
      tag -
      Returns:
    • getXmlTagValue

      public static String getXmlTagValue​(String source, String tag, int position)
      get tag value
      Parameters:
      source -
      tag -
      position - : starts at 1
      Returns:
    • isXmlFile

      public static boolean isXmlFile​(String filename)
      return true if file is xml file
      Parameters:
      filename -
      Returns:
    • isValidXmlString

      public static boolean isValidXmlString​(String xmlString)
      validates if xml string is valid xml
      Parameters:
      xmlString -
      Returns:
    • prettyFormat

      public static String prettyFormat​(String input, int indent)
    • removeXmlNameSpace

      public static String removeXmlNameSpace​(String xmlString)
      remove namespaces from xml gets namespace tags in list and removes them
      Parameters:
      xmlString -
      Returns:
    • cleanNameSpace

      public static Document cleanNameSpace​(Document doc)
      remove namespaces from xml gets namespace tags in list and removes them
      Parameters:
      doc -
      Returns: