Package core.apiCore.helpers
Class XmlHelper
java.lang.Object
core.apiCore.helpers.XmlHelper
public class XmlHelper extends Object
-
Constructor Summary
Constructors Constructor Description XmlHelper() -
Method Summary
Modifier and Type Method Description static DocumentcleanNameSpace(Document doc)remove namespaces from xml gets namespace tags in list and removes themstatic StringconvertDocumentToString(Document doc)Convert a contents of a Document to a Stringstatic StringconvertXmlFileToString(Path filePath)Convert contents of an XML file to a stringstatic DocumentconvertXmlStringToDocument(String xmlStr)Convert a String in XML format to a Documentstatic NodeListgetNodeList(String xpathString, String xmlString)Get text value of the node specified by xpathstatic StringgetNodeValue(String xpathString, String xmlString)Get text value of the node specified by xpathstatic StringgetRequestBodyFromXmlTemplate(ServiceObject serviceObject)if request body is empty, return xml template string if request body contains xml tag, replace tag with value eg.static StringgetXmlTagValue(String value, String tag)get first matching tag valuestatic StringgetXmlTagValue(String source, String tag, int position)get tag valuestatic StringgetXpathFromXml(String xml, String xpath)get xpath value form xml string test out xpath values at: https://www.freeformatter.com/xpath-tester.html#ad-outputstatic StringgetXpathValueFromJson(String json, String xpath)converts json string to xml and gets xpath value from itstatic booleanisValidXmlString(String xmlString)validates if xml string is valid xmlstatic booleanisXmlFile(String filename)return true if file is xml filestatic StringjsonToXml(String json)convert json string to xml stringstatic StringprettyFormat(String input, int indent)static DocumentreadFile(String inputFilePath)Read a XML file And get a Document retrying And catching interruptions from other threads.static StringremoveXmlNameSpace(String xmlString)remove namespaces from xml gets namespace tags in list and removes themstatic StringreplaceGroup(String regex, String source, int groupToReplace, int groupOccurrence, String replacement)generic replace value using regex using indexstatic StringreplaceRequestTagValues(String requestbody, String xmlString)replaces request header tag values eg.static StringreplaceTagValue(String xml, String tag, String value)replace tag value in xml for all occurrencesstatic StringreplaceTagValue(String xml, String tag, String value, int position)replace tag value in xml string at index
-
Constructor Details
-
XmlHelper
public XmlHelper()
-
-
Method Details
-
convertDocumentToString
Convert a contents of a Document to a String- Parameters:
doc-- Returns:
- String
-
convertXmlStringToDocument
Convert a String in XML format to a Document- Parameters:
xmlStr-- Returns:
- Document
-
convertXmlFileToString
Convert contents of an XML file to a string- Parameters:
filePath-- Returns:
- String
-
readFile
Read a XML file And get a Document retrying And catching interruptions from other threads.- Parameters:
inputFilePath-- Returns:
- Document
-
getNodeValue
Get text value of the node specified by xpath- Parameters:
xpathString-xmlString-- Returns:
- String
-
getNodeList
Get text value of the node specified by xpath- Parameters:
xpathString-xmlString-- Returns:
- String
-
getXpathValueFromJson
converts json string to xml and gets xpath value from it- Parameters:
json-xpath-- Returns:
- result list as string separated by ","
-
getXpathFromXml
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
convert json string to xml string- Parameters:
json-- Returns:
-
getRequestBodyFromXmlTemplate
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
replace tag value in xml string at index- Parameters:
position- : starts at 1tag-value-- Returns:
-
replaceTagValue
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
replaces request header tag values eg. "soi:EquipmentID:1:<@_TIME_16>" tag: soi:EquipmentID, position: 1, value: <@_TIME_16>- Parameters:
serviceObject-- Returns:
-
getXmlTagValue
get first matching tag value- Parameters:
requestBody-tag-- Returns:
-
getXmlTagValue
get tag value- Parameters:
source-tag-position- : starts at 1- Returns:
-
isXmlFile
return true if file is xml file- Parameters:
filename-- Returns:
-
isValidXmlString
validates if xml string is valid xml- Parameters:
xmlString-- Returns:
-
prettyFormat
-
removeXmlNameSpace
remove namespaces from xml gets namespace tags in list and removes them- Parameters:
xmlString-- Returns:
-
cleanNameSpace
remove namespaces from xml gets namespace tags in list and removes them- Parameters:
doc-- Returns:
-