public class XpathXmlUpgrader extends Object
| Constructor and Description |
|---|
XpathXmlUpgrader() |
| Modifier and Type | Method and Description |
|---|---|
static Optional<Document> |
read(File inputFile)
Read an XML document from a
file. |
static Optional<Document> |
read(InputStream input)
Read an XML document from an
input stream. |
static void |
transform(File file,
String xPathExpression,
Consumer<Node> transformation)
Read XML from
file, apply transformation on nodes matching xPathExpression
and write results back to the same file. |
static Document |
visit(Document document,
String xPathExpression,
Consumer<Node> visitor)
Iterate over elements of
document, performing actions on each visited node matching xPathExpression. |
static void |
visit(File file,
String xPathExpression,
Consumer<Node> visitor)
Read XML from
file, performing actions on each visited node matching xPathExpression. |
static void |
write(Document dom,
File outputFile)
Write an XML document to a
file. |
static void |
write(Document dom,
OutputStream output)
Write an XML document to an
output stream. |
public static void visit(File file, String xPathExpression, Consumer<Node> visitor)
file, performing actions on each visited node matching xPathExpression. The visitor should not perform transformation on accepted nodes, as the modifications will not be
persisted.file - XML file to transformxPathExpression - nodes to be modifiedvisitor - action to execute on each matching nodetransform(File, String, Consumer)public static void transform(File file, String xPathExpression, Consumer<Node> transformation)
file, apply transformation on nodes matching xPathExpression
and write results back to the same file. Note: transformation is performed in-place, i.e. node
is not being replaced by a new one.file - XML file to transformxPathExpression - nodes to be modifiedtransformation - how to modify nodesvisit(File, String, Consumer)public static Document visit(Document document, String xPathExpression, Consumer<Node> visitor)
document, performing actions on each visited node matching xPathExpression. The visitor may apply in-place transformation.document - document transformxPathExpression - nodes to be modifiedvisitor - action to execute on each matching nodepublic static Optional<Document> read(File inputFile)
file.inputFile - XML filepublic static Optional<Document> read(InputStream input)
input stream.input - input streampublic static void write(Document dom, File outputFile)
file.dom - documentoutputFile - XML filepublic static void write(Document dom, OutputStream output)
output stream.dom - documentoutput - output streamCopyright © 2022 Atlassian Software Systems Pty Ltd. All rights reserved.