public class XmlHelper extends Object
| Constructor and Description |
|---|
XmlHelper() |
| Modifier and Type | Method and Description |
|---|---|
static String |
convertDocumentToString(Document doc)
Convert a contents of a Document to a String
|
static String |
convertXmlFileToString(Path filePath)
Convert contents of an XML file to a string
|
static Document |
convertXmlStringToDocument(String xmlStr)
Convert a String in XML format to a Document
|
static NodeList |
getNodeList(String xpathString,
String xmlString)
Get text value of the node specified by xpath
|
static String |
getNodeValue(String xpathString,
String xmlString)
Get text value of the node specified by xpath
|
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.
|
static String |
getXmlTagValue(String value,
String tag)
get first matching tag value
|
static String |
getXmlTagValue(String source,
String tag,
int position)
get tag value
|
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
|
static String |
getXpathValueFromJson(String json,
String xpath)
converts json string to xml and gets xpath value from it
|
static boolean |
isValidXmlString(String xmlString)
validates if xml string is valid xml
|
static boolean |
isXmlFile(String filename)
return true if file is xml file
|
static String |
jsonToXml(String json)
convert json string to xml string
|
static String |
prettyFormat(String input,
int indent) |
static Document |
readFile(String inputFilePath)
Read a XML file And get a Document retrying And catching interruptions from
other threads.
|
static String |
replaceGroup(String regex,
String source,
int groupToReplace,
int groupOccurrence,
String replacement)
generic replace value using regex using index
|
static String |
replaceRequestTagValues(ServiceObject serviceObject)
replaces request header tag values eg.
|
static String |
replaceTagValue(String xml,
String tag,
String value)
replace tag value in xml for all occurrences
|
static String |
replaceTagValue(String xml,
String tag,
String value,
int position)
replace tag value in xml string at index
|
public static String convertDocumentToString(Document doc)
doc - public static Document convertXmlStringToDocument(String xmlStr)
xmlStr - public static String convertXmlFileToString(Path filePath)
filePath - public static Document readFile(String inputFilePath)
inputFilePath - public static String getNodeValue(String xpathString, String xmlString)
xpathString - xmlString - public static NodeList getNodeList(String xpathString, String xmlString)
xpathString - xmlString - public static String getXpathValueFromJson(String json, String xpath)
json - xpath - public static String getXpathFromXml(String xml, String xpath)
xml - xpath - public static String jsonToXml(String json)
json - public static String getRequestBodyFromXmlTemplate(ServiceObject serviceObject)
serviceObject - public static String replaceTagValue(String xml, String tag, String value, int position)
position: - starts at 1tag - value - public static String replaceTagValue(String xml, String tag, String value)
xml - tag - value - public static String replaceGroup(String regex, String source, int groupToReplace, int groupOccurrence, String replacement)
regex - source - groupToReplace - groupOccurrence - replacement - public static String replaceRequestTagValues(ServiceObject serviceObject)
serviceObject - public static String getXmlTagValue(String value, String tag)
requestBody - tag - public static String getXmlTagValue(String source, String tag, int position)
source - tag - position: - starts at 1public static boolean isXmlFile(String filename)
filename - public static boolean isValidXmlString(String xmlString)
xmlString - Copyright © 2020. All rights reserved.