public class XmlUtils extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
XmlUtils.TransformerRuntimeException
Runtime version of
TransformerException |
| Constructor and Description |
|---|
XmlUtils() |
| Modifier and Type | Method and Description |
|---|---|
static void |
checkRootElement(Document document,
String expectedRootElementName)
Check that the name of root element of the given
document matches the given expectedRootElementName |
static void |
flush(Document in,
OutputStream out)
Serialise the given
Document in the given OutputStream. |
static void |
flush(Document in,
OutputStream out,
Map<String,String> outputProperties)
Serialise the given
Document in the given OutputStream. |
static void |
flush(Document in,
Result out,
Map<String,String> outputProperties)
|
static void |
flush(Document in,
Writer out)
|
static void |
flush(Document in,
Writer out,
Map<String,String> outputProperties)
|
static Element |
getUniqueElement(Document document,
String xpathExpression)
Returns the unique XML element matching the given
xpathExpression |
static Element |
getUniqueElement(Element element,
String xpathExpression)
Returns the unique XML element matching the given
xpathExpression |
static Element |
getUniqueElement(Node node,
String xpathExpression)
Returns the unique XML element matching the given
xpathExpression |
static void |
insertSiblingAfter(Element newElement,
Element sibling)
Insert the given
newElement just next to the given sibling, after it. |
static Document |
loadXmlDocumentFromFile(File file)
Load the given
file as an XML document. |
static Document |
loadXmlDocumentFromPath(Path path)
Load the given
path as an XML document. |
static Document |
loadXmlDocumentFromStream(InputStream in)
Load the given
InputStream as an XML document. |
@Nonnull public static Element getUniqueElement(@Nonnull Document document, @Nonnull String xpathExpression) throws RuntimeException
xpathExpressiondocument - xpathExpression - xpath expression to find the elementRuntimeException - 0 or more than 1 matching element found@Nonnull public static Element getUniqueElement(@Nonnull Element element, @Nonnull String xpathExpression)
xpathExpressionelement - xpathExpression - xpath expression to find the elementRuntimeException - 0 or more than 1 matching element found@Nonnull public static Element getUniqueElement(@Nonnull Node node, @Nonnull String xpathExpression)
xpathExpressionnode - xpathExpression - xpath expression to find the nodeRuntimeException - 0 or more than 1 matching element found@Nonnull public static Document loadXmlDocumentFromFile(@Nonnull File file) throws ParserConfigurationException, IOException, SAXException
file as an XML document.file - ParserConfigurationExceptionIOExceptionSAXException@Nonnull public static Document loadXmlDocumentFromPath(@Nonnull Path path) throws ParserConfigurationException, IOException, SAXException
path as an XML document.file - ParserConfigurationExceptionIOExceptionSAXException@Nonnull public static Document loadXmlDocumentFromStream(@Nonnull InputStream in) throws ParserConfigurationException, IOException, SAXException
InputStream as an XML document.file - ParserConfigurationExceptionIOExceptionSAXExceptionpublic static void checkRootElement(@Nonnull Document document, @Nullable String expectedRootElementName)
document matches the given expectedRootElementNamedocument - expectedRootElementName - public static void flush(@Nonnull Document in, @Nonnull OutputStream out) throws XmlUtils.TransformerRuntimeException
Document in the given OutputStream.in - out - XmlUtils.TransformerRuntimeExceptionpublic static void flush(@Nonnull Document in, @Nonnull Writer out) throws XmlUtils.TransformerRuntimeException
in - out - XmlUtils.TransformerRuntimeExceptionpublic static void flush(@Nonnull Document in, @Nonnull OutputStream out, @Nullable Map<String,String> outputProperties) throws XmlUtils.TransformerRuntimeException
Document in the given OutputStream.in - outputProperties - see Transformer.setOutputProperty(String, String)out - XmlUtils.TransformerRuntimeExceptionpublic static void flush(@Nonnull Document in, @Nonnull Writer out, @Nullable Map<String,String> outputProperties) throws XmlUtils.TransformerRuntimeException
in - outputProperties - see Transformer.setOutputProperty(String, String)out - XmlUtils.TransformerRuntimeExceptionpublic static void flush(@Nonnull Document in, @Nonnull Result out, @Nullable Map<String,String> outputProperties) throws XmlUtils.TransformerRuntimeException
in - outputProperties - see Transformer.setOutputProperty(String, String)out - XmlUtils.TransformerRuntimeExceptionCopyright © 2013. All Rights Reserved.