public class XmlReader extends java.lang.Object implements ResponseReader
| Constructor and Description |
|---|
XmlReader(java.lang.String xml)
An xml reader.
|
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
asPrettyString() |
<T> T |
from(java.lang.Class<T> clazz)
Deserialize the XML into specified class.
|
static java.lang.String |
prettyFormat(java.lang.String input,
int indent)
Converts the XML document to a nicely formatted string.
|
java.lang.String |
textContent(java.lang.String selector)
Search a XML element's children for the requested element and returns the text content.
|
public XmlReader(java.lang.String xml)
throws javax.xml.parsers.ParserConfigurationException,
org.xml.sax.SAXException,
java.io.IOException
xml - XML stringjavax.xml.parsers.ParserConfigurationExceptionjava.io.IOExceptionorg.xml.sax.SAXExceptionpublic java.lang.String textContent(java.lang.String selector)
throws javax.xml.parsers.ParserConfigurationException,
org.xml.sax.SAXException,
java.io.IOException,
javax.xml.xpath.XPathExpressionException
Example:
serviceResponse returnLength="1">
output name="documentId">idd_CD1C398E-1F25-436D-B76A-9E293BB426F5/output>
/serviceResponse>
String documentId = reader.getXmlReader().textContent("///output[@name='documentId']");
selector - search pathjavax.xml.parsers.ParserConfigurationExceptionorg.xml.sax.SAXExceptionjava.io.IOExceptionjavax.xml.xpath.XPathExpressionExceptionpublic java.lang.String asPrettyString()
asPrettyString in interface ResponseReaderpublic static java.lang.String prettyFormat(java.lang.String input,
int indent)
input - XML stringindent - number of spaces to indent each linepublic <T> T from(java.lang.Class<T> clazz)
throws javax.xml.bind.JAXBException
T - The type of the desired classclazz - Class of object to deserialize tojavax.xml.bind.JAXBException