Class XMLUtils

java.lang.Object
io.github.the_sdet.xml.XMLUtils

public class XMLUtils extends Object
This class handles all JSON related Utilities and Helper methods
Author:
Pabitra Swain ([email protected])
  • Constructor Details

    • XMLUtils

      public XMLUtils()
  • Method Details

    • readXML

      public static Document readXML(String filePath) throws Exception
      Reads an XML file and returns a Document object representing its structure.
      Parameters:
      filePath - The path to the XML file to be read.
      Returns:
      A Document object representing the XML structure.
      Throws:
      Exception - if an error occurs during parsing or reading the file.
    • saveXML

      public static void saveXML(Document doc, String filePath) throws Exception
      Saves an XML document to a file.
      Parameters:
      doc - The Document object representing the XML structure.
      filePath - The path to the file where the XML document will be saved.
      Throws:
      Exception - if an error occurs during the transformation or writing to the file.
    • updateXMLData

      public static void updateXMLData(Document doc, String elementXpath, String value) throws Exception
      Updates the value of an XML element identified by its XPath.
      Parameters:
      doc - The Document object representing the XML structure.
      elementXpath - The XPath expression to identify the XML element.
      value - The new value to set for the XML element.
      Throws:
      Exception - if an error occurs during XPath evaluation or updating the XML element.
    • deleteXMLNode

      public static void deleteXMLNode(Document doc, String elementXpath) throws Exception
      Deletes an XML node identified by its XPath.
      Parameters:
      doc - The Document object representing the XML structure.
      elementXpath - The XPath expression to identify the XML node.
      Throws:
      Exception - if an error occurs during XPath evaluation or deleting the XML node.
    • getContentFromXmlResponse

      public static String getContentFromXmlResponse(String response, String regex)
      Extracts content from an XML response using a regular expression.
      Parameters:
      response - The XML response string.
      regex - The regular expression to match the content.
      Returns:
      The content extracted from the XML response.