public class XMLUpdateUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ATTR_NAME_ENC
The
encoding attribute name of an XML declaration. |
static java.lang.String |
CLASSNAME
The full class name for this file.
|
static java.lang.String |
COPYRIGHT
Copyright statement.
|
Constructor and Description |
---|
XMLUpdateUtil() |
Modifier and Type | Method and Description |
---|---|
static void |
appendChild(org.w3c.dom.Document doc,
org.w3c.dom.NodeList matchedNodeList,
org.w3c.dom.Node newNode)
Appends a child node to the node(s) in a node list.
|
static void |
appendChild(org.w3c.dom.Document doc,
java.lang.String path,
org.w3c.dom.Node newNode)
Appends a child node to the node(s) pointed to by the XPath.
|
static void |
appendChild(org.w3c.dom.Document doc,
java.lang.String path,
org.w3c.dom.NodeList newNodes)
Appends a set of nodes to the node(s) pointed to by the XPath.
|
static void |
appendString(org.w3c.dom.Document doc,
java.lang.String path,
java.lang.String value)
Appends a string to the node(s) pointed to by the XPath.
|
static void |
appendString(org.w3c.dom.NodeList matchedNodeList,
java.lang.String value)
Appends a string to the node(s) in a node list.
|
static int |
countMatches(org.w3c.dom.Document doc,
java.lang.String path)
Returns the number of XPath matches in the DOM tree.
|
static void |
delete(org.w3c.dom.Document doc,
java.lang.String path)
Removes the node(s) pointed to by the XPath.
|
static void |
delete(org.w3c.dom.NodeList matchedNodeList)
Removes the nodes present in list of nodes indicated by
matchedNodeList |
static boolean |
escapeEntityReferences(java.io.File xmlFile)
Escapes entity references in an XML file.
|
static boolean |
escapeEntityReferences(java.io.File inputFile,
java.io.File outputFile)
Reads content of an input XML file, escapes entity references, and writes
the modified content to another XML file.
|
static java.lang.String |
getEncoding(java.io.File xmlFile)
Returns the encoding of an XML file.
|
static java.lang.String |
getEscapedAmp()
Returns the escaped '&' string.
|
static java.lang.String |
getXMLDeclaration(java.io.File xmlFile)
Returns the XML declaration string in an XML file.
|
static void |
insertAfter(org.w3c.dom.Document doc,
org.w3c.dom.NodeList matchedNodeList,
org.w3c.dom.Node newNode)
Inserts a node after a list of node(s).
|
static void |
insertAfter(org.w3c.dom.Document doc,
org.w3c.dom.NodeList matchedNodeList,
org.w3c.dom.NodeList newNodes)
Inserts a set of node after a list of node(s).
|
static void |
insertAfter(org.w3c.dom.Document doc,
java.lang.String path,
org.w3c.dom.Node newNode)
Inserts a node after the node(s) pointed to by the XPath.
|
static void |
insertAfter(org.w3c.dom.Document doc,
java.lang.String path,
org.w3c.dom.NodeList newNodes)
Inserts a set of node after the node(s) pointed to by the XPath.
|
static void |
insertBefore(org.w3c.dom.Document doc,
org.w3c.dom.NodeList matchedNodeList,
org.w3c.dom.Node newNode)
Inserts a node before a list of node(s) that match XPath as siblings.
|
static void |
insertBefore(org.w3c.dom.Document doc,
org.w3c.dom.NodeList matchedNodeList,
org.w3c.dom.NodeList newNodes)
Inserts a set of node before a list of node(s).
|
static void |
insertBefore(org.w3c.dom.Document doc,
java.lang.String path,
org.w3c.dom.Node newNode)
Inserts a node before the node(s) pointed to by the XPath.
|
static void |
insertBefore(org.w3c.dom.Document doc,
java.lang.String path,
org.w3c.dom.NodeList newNodes)
Inserts a set of node before the node(s) pointed to by the XPath.
|
static void |
insertCommentAfter(org.w3c.dom.Document doc,
org.w3c.dom.NodeList matchedNodeList,
java.lang.String comment)
Inserts a comment after the node(s) pointed to by the XPath.
|
static void |
insertCommentBefore(org.w3c.dom.Document doc,
org.w3c.dom.NodeList matchedNodeList,
java.lang.String comment)
Inserts a comment before the node(s) pointed to by the XPath.
|
static boolean |
matches(org.w3c.dom.Document doc,
java.lang.String path)
Checks whether a given XPath matches any node in the DOM tree.
|
static org.w3c.dom.Document |
readXMLFile(java.io.File inputFile)
Reads an XML file and returns its DOM representation.
|
static org.w3c.dom.Document |
readXMLFile(java.io.File inputFile,
java.lang.String encoding)
Reads an XML file and returns its DOM representation.
|
static void |
replace(org.w3c.dom.Document doc,
org.w3c.dom.NodeList matchedNodeList,
org.w3c.dom.Node newNode)
Replace the node(s) in a node list with the new node that match XPath with Nodes.
|
static void |
replace(org.w3c.dom.Document doc,
org.w3c.dom.NodeList matchedNodeList,
org.w3c.dom.NodeList newNodes)
Replaces the node(s) in a list with the new list of nodes.
|
static void |
replace(org.w3c.dom.Document doc,
java.lang.String path,
org.w3c.dom.Node newNode)
Replaces the node(s) pointed to by the XPath with the new node.
|
static void |
replace(org.w3c.dom.Document doc,
java.lang.String path,
org.w3c.dom.NodeList newNodes)
Replaces the node(s) pointed to by the XPath with the new list of nodes.
|
static org.w3c.dom.NodeList |
selectNodeList(org.w3c.dom.Document doc,
java.lang.String path)
Returns a list of matched node(s) pointed to by the XPath.
|
static java.lang.String |
serializeToString(org.w3c.dom.Document doc,
org.apache.xml.serialize.OutputFormat of)
Serializes a DOM to a string.
|
static java.lang.String |
serializeToString(org.w3c.dom.Document doc,
java.lang.String encoding,
boolean indenting)
Serializes a DOM to a string.
|
static void |
setAttribute(org.w3c.dom.Document doc,
java.lang.String path,
java.lang.String name,
java.lang.String value)
Sets an attribute in the node(s) pointed to by the XPath.
|
static void |
setAttribute(org.w3c.dom.NodeList matchedNodeList,
java.lang.String name,
java.lang.String value)
Sets an attribute in the node(s) in a node list.
|
static boolean |
unescapeEntityReferences(java.io.File inputFile)
Unescapes entity references in an XML file.
|
static boolean |
unescapeEntityReferences(java.io.File inputFile,
java.io.File outputFile)
Reads content of an input XML file, unescapes entity references, and
writes the modified content to another XML file.
|
static void |
writeXMLFile(org.w3c.dom.Document doc,
java.io.File outputFile,
org.apache.xml.serialize.OutputFormat of)
Writes a DOM to a file.
|
static void |
writeXMLFile(org.w3c.dom.Document doc,
java.io.File outputFile,
java.lang.String encoding,
boolean indenting)
Writes a DOM to a file.
|
public static final java.lang.String COPYRIGHT
public static final java.lang.String CLASSNAME
public static final java.lang.String ATTR_NAME_ENC
encoding
attribute name of an XML declaration.public static void appendChild(org.w3c.dom.Document doc, org.w3c.dom.NodeList matchedNodeList, org.w3c.dom.Node newNode)
doc
- The DOM tree to be modified.matchedNodeList
- The list of node(s) to which child node is added.newNode
- The new node to be added.public static void appendChild(org.w3c.dom.Document doc, java.lang.String path, org.w3c.dom.Node newNode) throws javax.xml.transform.TransformerException, NoXPathMatchException
doc
- The DOM tree to be modified.path
- The XPath to the node(s) to which the child node is added.newNode
- The new node to be added.javax.xml.transform.TransformerException
NoXPathMatchException
public static void appendChild(org.w3c.dom.Document doc, java.lang.String path, org.w3c.dom.NodeList newNodes) throws javax.xml.transform.TransformerException, NoXPathMatchException
doc
- The DOM tree to be modified.path
- The XPath to the node(s) to which the child node is added.newNodes
- The list of new nodes.javax.xml.transform.TransformerException
NoXPathMatchException
public static void delete(org.w3c.dom.NodeList matchedNodeList)
matchedNodeList
matchedNodeList
- The list of node(s) to be deleted.public static void delete(org.w3c.dom.Document doc, java.lang.String path) throws javax.xml.transform.TransformerException, NoXPathMatchException
doc
- The DOM tree to be modified.path
- The XPath to the node(s) to be deleted.javax.xml.transform.TransformerException
NoXPathMatchException
public static void insertBefore(org.w3c.dom.Document doc, org.w3c.dom.NodeList matchedNodeList, org.w3c.dom.Node newNode)
doc
- The DOM tree to be modified.matchedNodeList
- The list of node(s) before which the new node is inserted.newNode
- The new node to be inserted.public static void insertBefore(org.w3c.dom.Document doc, java.lang.String path, org.w3c.dom.Node newNode) throws javax.xml.transform.TransformerException, NoXPathMatchException
doc
- The DOM tree to be modified.path
- The XPath to the node(s) before which the new node is
inserted.newNode
- The new node to be inserted.javax.xml.transform.TransformerException
NoXPathMatchException
public static void insertBefore(org.w3c.dom.Document doc, org.w3c.dom.NodeList matchedNodeList, org.w3c.dom.NodeList newNodes) throws javax.xml.transform.TransformerException, NoXPathMatchException
doc
- The DOM tree to be modified.matchedNodeList
- The list of node(s) before which the new nodes are inserted.newNodes
- The list of new nodes.javax.xml.transform.TransformerException
NoXPathMatchException
public static void insertBefore(org.w3c.dom.Document doc, java.lang.String path, org.w3c.dom.NodeList newNodes) throws javax.xml.transform.TransformerException, NoXPathMatchException
doc
- The DOM tree to be modified.path
- The XPath to the node(s) before which the new nodes are
inserted.newNodes
- The list of new nodes.javax.xml.transform.TransformerException
NoXPathMatchException
public static void insertAfter(org.w3c.dom.Document doc, org.w3c.dom.NodeList matchedNodeList, org.w3c.dom.Node newNode) throws javax.xml.transform.TransformerException
doc
- The DOM tree to be modified.matchedNodeList
- The list of node(s) after which the new node is inserted.newNode
- The new node to be inserted.javax.xml.transform.TransformerException
public static void insertAfter(org.w3c.dom.Document doc, java.lang.String path, org.w3c.dom.Node newNode) throws javax.xml.transform.TransformerException, NoXPathMatchException
doc
- The DOM tree to be modified.path
- The XPath to the node after before which the new node is
inserted.newNode
- The new node to be inserted.javax.xml.transform.TransformerException
NoXPathMatchException
public static void insertAfter(org.w3c.dom.Document doc, org.w3c.dom.NodeList matchedNodeList, org.w3c.dom.NodeList newNodes) throws javax.xml.transform.TransformerException, NoXPathMatchException
doc
- The DOM tree to be modified.matchedNodeList
- The list of node(s) after which the new nodes are inserted.newNodes
- The list of new nodes.javax.xml.transform.TransformerException
NoXPathMatchException
public static void insertAfter(org.w3c.dom.Document doc, java.lang.String path, org.w3c.dom.NodeList newNodes) throws javax.xml.transform.TransformerException, NoXPathMatchException
doc
- The DOM tree to be modified.path
- The XPath to the node(s) after which the new nodes are
inserted.newNodes
- The list of new nodes.javax.xml.transform.TransformerException
NoXPathMatchException
public static void replace(org.w3c.dom.Document doc, org.w3c.dom.NodeList matchedNodeList, org.w3c.dom.Node newNode) throws javax.xml.transform.TransformerException
doc
- The DOM tree to be modified.matchedNodeList
- The list of node(s) to be replaced.newNode
- The replacement node.javax.xml.transform.TransformerException
public static void replace(org.w3c.dom.Document doc, java.lang.String path, org.w3c.dom.Node newNode) throws javax.xml.transform.TransformerException, NoXPathMatchException
doc
- The DOM tree to be modified.path
- The XPath to the node(s) to be replaced.newNode
- The replacement node.javax.xml.transform.TransformerException
NoXPathMatchException
public static void replace(org.w3c.dom.Document doc, org.w3c.dom.NodeList matchedNodeList, org.w3c.dom.NodeList newNodes) throws javax.xml.transform.TransformerException, NoXPathMatchException
doc
- The DOM tree to be modified.matchedNodeList
- The list of node(s) to be replaced.newNodes
- The list of replacement nodes.javax.xml.transform.TransformerException
NoXPathMatchException
public static void replace(org.w3c.dom.Document doc, java.lang.String path, org.w3c.dom.NodeList newNodes) throws javax.xml.transform.TransformerException, NoXPathMatchException
doc
- The DOM tree to be modified.path
- The XPath to the node(s) to be replaced.newNodes
- The list of replacement nodes.javax.xml.transform.TransformerException
NoXPathMatchException
public static void appendString(org.w3c.dom.NodeList matchedNodeList, java.lang.String value) throws javax.xml.transform.TransformerException
matchedNodeList
- The list of node(s) to which value is appended.value
- The value to be appended.javax.xml.transform.TransformerException
public static void appendString(org.w3c.dom.Document doc, java.lang.String path, java.lang.String value) throws javax.xml.transform.TransformerException, NoXPathMatchException
doc
- The DOM tree to be modified.path
- The XPath to the node(s) to which value is appended.value
- The value to be appended.javax.xml.transform.TransformerException
NoXPathMatchException
public static void setAttribute(org.w3c.dom.NodeList matchedNodeList, java.lang.String name, java.lang.String value) throws javax.xml.transform.TransformerException
matchedNodeList
- The list of element node(s) to which the new attribute is
added.name
- The new attribute name.value
- The new attribute value.javax.xml.transform.TransformerException
public static void setAttribute(org.w3c.dom.Document doc, java.lang.String path, java.lang.String name, java.lang.String value) throws javax.xml.transform.TransformerException, NoXPathMatchException
doc
- The DOM tree to be modified.path
- The XPath to the element node(s) to which the new attribute is
added.name
- The new attribute name.value
- The new attribute value.javax.xml.transform.TransformerException
NoXPathMatchException
public static void insertCommentBefore(org.w3c.dom.Document doc, org.w3c.dom.NodeList matchedNodeList, java.lang.String comment) throws javax.xml.transform.TransformerException, NoXPathMatchException
doc
- The DOM tree to be modified.matchedNodeList
- The list of node(s) before which the comment is added.comment
- The comment text.javax.xml.transform.TransformerException
NoXPathMatchException
public static void insertCommentAfter(org.w3c.dom.Document doc, org.w3c.dom.NodeList matchedNodeList, java.lang.String comment) throws javax.xml.transform.TransformerException, NoXPathMatchException
doc
- The DOM tree to be modified.matchedNodeList
- The list of node(s) after which the comment is added.comment
- The comment text.javax.xml.transform.TransformerException
NoXPathMatchException
public static boolean matches(org.w3c.dom.Document doc, java.lang.String path) throws javax.xml.transform.TransformerException
doc
- The DOM tree to be tested against.path
- The XPath to be searched.true
if XPath matches; false
otherwise.javax.xml.transform.TransformerException
public static int countMatches(org.w3c.dom.Document doc, java.lang.String path) throws javax.xml.transform.TransformerException
doc
- The DOM tree to be tested against.path
- The XPath to be searched.path
in doc
.javax.xml.transform.TransformerException
public static org.w3c.dom.NodeList selectNodeList(org.w3c.dom.Document doc, java.lang.String path) throws javax.xml.transform.TransformerException, NoXPathMatchException
doc
- The document to select node(s) from.path
- The XPath.javax.xml.transform.TransformerException
NoXPathMatchException
public static java.lang.String getEncoding(java.io.File xmlFile) throws java.io.IOException
xmlFile
- The XML file to be parsed.null
otherwise.java.io.IOException
public static java.lang.String getXMLDeclaration(java.io.File xmlFile) throws java.io.IOException
xmlFile
- The XML file to be parsed.null
otherwise.java.io.IOException
public static boolean escapeEntityReferences(java.io.File xmlFile) throws java.io.IOException
xmlFile
- The XML file in which entity references are escaped.true
if file is modified; false
otherwise.java.io.IOException
public static boolean escapeEntityReferences(java.io.File inputFile, java.io.File outputFile) throws java.io.IOException
inputFile
- The input XML file to get content from.outputFile
- The output XML file to write modified content to.true
if file is modified; false
otherwise.java.io.IOException
public static boolean unescapeEntityReferences(java.io.File inputFile) throws java.io.IOException
inputFile
- The XML file in which entity references are unescaped.true
if file is modified; false
otherwise.java.io.IOException
public static boolean unescapeEntityReferences(java.io.File inputFile, java.io.File outputFile) throws java.io.IOException
inputFile
- The input XML file to get content from.outputFile
- The output XML file to write modified content to.true
if file is modified; false
otherwise.java.io.IOException
public static java.lang.String getEscapedAmp()
public static org.w3c.dom.Document readXMLFile(java.io.File inputFile) throws java.io.IOException, org.xml.sax.SAXException
UTF-8
if not defined
in the XML file.inputFile
- The input XML file.java.io.IOException
org.xml.sax.SAXException
public static org.w3c.dom.Document readXMLFile(java.io.File inputFile, java.lang.String encoding) throws java.io.IOException, org.xml.sax.SAXException
inputFile
- The input file.encoding
- The encoding to be used for reading the XML file. If set to
null
, UTF-8
is assumed.java.io.IOException
org.xml.sax.SAXException
public static void writeXMLFile(org.w3c.dom.Document doc, java.io.File outputFile, java.lang.String encoding, boolean indenting) throws java.io.IOException
doc
- The DOM.outputFile
- The output XML file.encoding
- The encoding of the output XML file. If set to
null
, UTF-8
is assumed.indenting
- Whether to indent the output XML file.java.io.IOException
public static void writeXMLFile(org.w3c.dom.Document doc, java.io.File outputFile, org.apache.xml.serialize.OutputFormat of) throws java.io.IOException
doc
- The DOM.outputFile
- The output XML file.of
- The output format.java.io.IOException
public static java.lang.String serializeToString(org.w3c.dom.Document doc, java.lang.String encoding, boolean indenting) throws java.io.IOException
doc
- The DOM.encoding
- The encoding of the output XML file. If set to
null
, UTF-8
is assumed.indenting
- Whether to indent the output XML file.java.io.IOException
public static java.lang.String serializeToString(org.w3c.dom.Document doc, org.apache.xml.serialize.OutputFormat of) throws java.io.IOException
doc
- The DOM.of
- The output format.java.io.IOException