public class XmlUtils
extends java.lang.Object
Constructor and Description |
---|
XmlUtils() |
XmlUtils(org.xml.sax.EntityResolver er) |
XmlUtils(org.xml.sax.EntityResolver er,
javax.xml.namespace.NamespaceContext ctx,
javax.xml.parsers.DocumentBuilderFactory dbf) |
XmlUtils(org.xml.sax.EntityResolver er,
javax.xml.transform.URIResolver ur)
Deprecated.
URIResolver does nothing so use
XmlUtils(EntityResolver) instead. |
XmlUtils(org.xml.sax.EntityResolver er,
javax.xml.transform.URIResolver ur,
javax.xml.namespace.NamespaceContext ctx)
Deprecated.
URIResolver does nothing so use
XmlUtils(EntityResolver, NamespaceContext, DocumentBuilderFactory)
instead. |
XmlUtils(org.xml.sax.EntityResolver er,
javax.xml.transform.URIResolver ur,
javax.xml.namespace.NamespaceContext ctx,
javax.xml.parsers.DocumentBuilderFactory dbf)
Deprecated.
URIResolver does nothing so use
XmlUtils(EntityResolver, NamespaceContext, DocumentBuilderFactory)
instead. |
XmlUtils(javax.xml.namespace.NamespaceContext ctx)
Deprecated.
|
XmlUtils(javax.xml.namespace.NamespaceContext ctx,
javax.xml.parsers.DocumentBuilderFactory f) |
Modifier and Type | Method and Description |
---|---|
void |
appendNode(org.w3c.dom.Node newNode,
org.w3c.dom.Node parent)
Convenience method which appends a new Node to the children of a parent
|
<T> T |
castOrFail(java.lang.Object o,
java.lang.Class<T> type,
java.lang.String exceptionMsg) |
org.w3c.dom.Node |
createNode(java.lang.String xp)
Method which will create a Node path based on the supplied XPath
|
void |
deleteAttribute(java.lang.String name,
org.w3c.dom.Node n)
Method which deletes an attribute from the specified Node, which must be of
type org.w3c.dom.Element.
|
org.w3c.dom.Document |
getCurrentDoc() |
java.lang.String[] |
getMultipleTextItems(java.lang.String xp)
Method which returns an array of String representations of either a TEXT_NODE or an ATTRIBUTE_NODE, extracted from the Node
created by "setSource".
|
java.lang.String[] |
getMultipleTextItems(java.lang.String xp,
org.w3c.dom.Node documentNode)
Method which returns an array of String representations of either a TEXT_NODE or an ATTRIBUTE_NODE, extracted from the provided
Node.
|
org.w3c.dom.NodeList |
getNodeList(java.lang.String xp)
Method which returns a NodeList extracted from the Node created by the setSource method based on the provided xpath String.
|
org.w3c.dom.NodeList |
getNodeList(java.lang.String xp,
org.w3c.dom.Node documentNode)
Method which returns a NodeList extracted from the provided Node based on the provided xpath String.
|
java.lang.String |
getParseMessage()
Method which returns the success / fail message generated by the document
parser.
|
org.w3c.dom.Node |
getSingleNode(java.lang.String xp)
Method which returns a Node by applying the provided, this Node can either be modified directly using the DOM api or by using
the convenience methods in this class.
|
org.w3c.dom.Node |
getSingleNode(java.lang.String xp,
org.w3c.dom.Node n)
Method which returns a Node by applying the provided relative to the specified root Node.
|
java.lang.String |
getSingleTextItem(java.lang.String xp)
Method which returns a String representation of either a TEXT_NODE or an ATTRIBUTE_NODE, extracted from the Node created by
"setSource".
|
java.lang.String |
getSingleTextItem(java.lang.String xp,
org.w3c.dom.Node documentNode)
Method which returns a String representation of either a TEXT_NODE or an ATTRIBUTE_NODE, extracted from the provided Node.
|
void |
insertNodeBefore(org.w3c.dom.Node newNode,
org.w3c.dom.Node existingNode,
org.w3c.dom.Node parent)
Convenience method which enables a new Node to be added to a parent at a specified position, by specifying the Node to insert
before.
|
boolean |
isDocumentValid()
Method which indicates whether the file was valid
|
void |
removeNode(org.w3c.dom.Node toBeRemoved,
org.w3c.dom.Node parent)
Convenience method which removes a Node from the children of a parent
|
void |
reset()
Re-initialises the XmlUtils object.
|
void |
setAttribute(java.lang.String name,
java.lang.String value,
org.w3c.dom.Node n)
Method which sets an attribute on the specified Node, which must be of type
org.w3c.dom.Element.
|
void |
setAttribute(java.lang.String xp,
java.lang.String name,
java.lang.String value)
Method which sets an attribute on the specified Node, which must be of type
org.w3c.dom.Element.
|
void |
setNodeValue(java.lang.String value,
org.w3c.dom.Node n)
Method which updates the Text value of a specified Node
|
void |
setNodeValue(java.lang.String xp,
java.lang.String value)
Method which modifies the value of the Node returned by the XPath query
specified.
|
void |
setNodeValue(java.lang.String xp,
java.lang.String v,
org.w3c.dom.Node root)
Method which modifies the value of the Node returned by the XPath query
specified, relative to the provided parent node.
|
void |
setSchema(java.lang.String uri)
Method added to specify the Schema to Validate against.
|
void |
setSource(org.xml.sax.InputSource xml)
Method which sets the source XML document for this class.
|
void |
setSource(java.io.InputStream xml)
Method which sets the source XML document for this class.
|
void |
setSource(org.w3c.dom.Node node)
Method which sets the source XML document for this class.
|
void |
setSource(java.io.Reader xml)
Method which sets the source XML document for this class.
|
void |
writeDocument(org.w3c.dom.Node node,
java.io.OutputStream output)
Method which writes a Document Node to the specified Writer using
ISO-8859-1 encoding
|
void |
writeDocument(org.w3c.dom.Node node,
java.io.OutputStream output,
java.lang.String encoding)
Method which writes a Document Node to the specified Writer using the
specified encoding
|
void |
writeDocument(org.w3c.dom.Node node,
java.io.Writer writer)
Method which writes a Document Node to the specified OutputStream using the
specified encoding
|
void |
writeDocument(org.w3c.dom.Node node,
java.io.Writer writer,
java.lang.String encoding)
Write the node to the specified writer.
|
void |
writeDocument(java.io.OutputStream output)
Method which writes the document set by setSource to the specified
OutputStream using ISO-8859-1 encoding
|
void |
writeDocument(java.io.OutputStream output,
java.lang.String encoding)
Method which writes a Document Node to the specified OutputStream using the
specified encoding
|
void |
writeDocument(java.io.Writer output)
Method which writes the document set by setSource to the specified Writer
using ISO-8859-1 encoding
|
void |
writeDocument(java.io.Writer output,
java.lang.String encoding)
Method which writes a Document Node to the specified Writer using the
specified encoding
|
public XmlUtils()
public XmlUtils(org.xml.sax.EntityResolver er)
@Deprecated public XmlUtils(javax.xml.namespace.NamespaceContext ctx)
public XmlUtils(javax.xml.namespace.NamespaceContext ctx, javax.xml.parsers.DocumentBuilderFactory f)
@Deprecated @Removal(version="4.0.0") public XmlUtils(org.xml.sax.EntityResolver er, javax.xml.transform.URIResolver ur)
XmlUtils(EntityResolver)
instead.@Deprecated @Removal(version="4.0.0") public XmlUtils(org.xml.sax.EntityResolver er, javax.xml.transform.URIResolver ur, javax.xml.namespace.NamespaceContext ctx)
XmlUtils(EntityResolver, NamespaceContext, DocumentBuilderFactory)
instead.@Deprecated @Removal(version="4.0.0") public XmlUtils(org.xml.sax.EntityResolver er, javax.xml.transform.URIResolver ur, javax.xml.namespace.NamespaceContext ctx, javax.xml.parsers.DocumentBuilderFactory dbf)
XmlUtils(EntityResolver, NamespaceContext, DocumentBuilderFactory)
instead.public XmlUtils(org.xml.sax.EntityResolver er, javax.xml.namespace.NamespaceContext ctx, javax.xml.parsers.DocumentBuilderFactory dbf)
public void setSchema(java.lang.String uri) throws java.lang.Exception
uri
- the URI to validate against.java.lang.Exception
- on error.public void setSource(org.xml.sax.InputSource xml)
xml
- the InputSourcepublic void setSource(java.io.Reader xml)
xml
- the Readerpublic void setSource(java.io.InputStream xml)
xml
- the inputstream for the sourcepublic void setSource(org.w3c.dom.Node node)
node
- a Node object of type Documentpublic java.lang.String getSingleTextItem(java.lang.String xp, org.w3c.dom.Node documentNode)
xp
- the Xpath querydocumentNode
- the Node to operate on.public java.lang.String getSingleTextItem(java.lang.String xp)
xp
- the Xpathpublic java.lang.String[] getMultipleTextItems(java.lang.String xp, org.w3c.dom.Node documentNode)
xp
- the xpathdocumentNode
- the starting node.public java.lang.String[] getMultipleTextItems(java.lang.String xp)
xp
- the Xpath query.public org.w3c.dom.NodeList getNodeList(java.lang.String xp, org.w3c.dom.Node documentNode)
xp
- the Xpath querydocumentNode
- the Node to search on.public org.w3c.dom.NodeList getNodeList(java.lang.String xp)
xp
- the Xpath querypublic org.w3c.dom.Node getSingleNode(java.lang.String xp)
xp
- the XPath which will return the Nodepublic org.w3c.dom.Node getSingleNode(java.lang.String xp, org.w3c.dom.Node n)
xp
- the XPath which will return the Noden
- the root node to apply the XPath topublic void reset() throws java.lang.Exception
java.lang.Exception
- on any error.public boolean isDocumentValid()
public java.lang.String getParseMessage()
public org.w3c.dom.Node createNode(java.lang.String xp) throws java.lang.Exception
xp
- the xpath.java.lang.Exception
- on error.public void setNodeValue(java.lang.String xp, java.lang.String value) throws java.lang.Exception
xp
- the XPath which will return the Node to be updatedvalue
- the new value to set the node tojava.lang.Exception
- on error.public void setNodeValue(java.lang.String xp, java.lang.String v, org.w3c.dom.Node root) throws java.lang.Exception
xp
- the XPath which will return the Node to be updatedv
- the new value to set the node toroot
- the root node to apply the XPath tojava.lang.Exception
- on error.public void setNodeValue(java.lang.String value, org.w3c.dom.Node n) throws java.lang.Exception
value
- the new Text valuen
- the node to be modifiedjava.lang.Exception
- on error.public void setAttribute(java.lang.String xp, java.lang.String name, java.lang.String value) throws java.lang.Exception
xp
- to retrieve the node to be modifiedname
- the attribute namevalue
- the new valuejava.lang.Exception
- on error.public void setAttribute(java.lang.String name, java.lang.String value, org.w3c.dom.Node n) throws java.lang.Exception
name
- the attribute namevalue
- the new valuen
- the node to be modifiedjava.lang.Exception
- on error.public void deleteAttribute(java.lang.String name, org.w3c.dom.Node n) throws java.lang.Exception
name
- the attribute namen
- the node to be modifiedjava.lang.Exception
- on error.public void insertNodeBefore(org.w3c.dom.Node newNode, org.w3c.dom.Node existingNode, org.w3c.dom.Node parent) throws java.lang.Exception
// Example of how to insert a Node as the 3rd child of a parent
Node p = xmlUtils.getSingleNode("/mydoc/parent");
Node c = xmlUtils.getSingleNode("/mydoc/parent/child[4]");
Node n = // Node creation code here;
xmlUtils.insertNodeBefore(newNode, child, parent);
newNode
- the Node to be addedexistingNode
- the Node to insert beforeparent
- the parent Nodejava.lang.Exception
- on error.public void appendNode(org.w3c.dom.Node newNode, org.w3c.dom.Node parent) throws java.lang.Exception
newNode
- the Node to be addedparent
- the parent Nodejava.lang.Exception
- on error.public void removeNode(org.w3c.dom.Node toBeRemoved, org.w3c.dom.Node parent) throws java.lang.Exception
toBeRemoved
- the Node to be Removedparent
- the parent Nodejava.lang.Exception
- on error.public void writeDocument(java.io.OutputStream output) throws java.lang.Exception
output
- the Outputstreamjava.lang.Exception
- on error.public void writeDocument(java.io.Writer output) throws java.lang.Exception
output
- the Outputstreamjava.lang.Exception
- on error.public void writeDocument(java.io.OutputStream output, java.lang.String encoding) throws java.lang.Exception
encoding
- the encoding type.output
- the Outputstreamjava.lang.Exception
- on error.public void writeDocument(java.io.Writer output, java.lang.String encoding) throws java.lang.Exception
encoding
- the encoding type.output
- the Outputstreamjava.lang.Exception
- on error.public void writeDocument(org.w3c.dom.Node node, java.io.OutputStream output) throws java.lang.Exception
node
- the Node to write.output
- the Outputstream to use.java.lang.Exception
- on error.public void writeDocument(org.w3c.dom.Node node, java.io.Writer writer) throws java.lang.Exception
node
- the node to write.writer
- the Writerjava.lang.Exception
- on error.public void writeDocument(org.w3c.dom.Node node, java.io.OutputStream output, java.lang.String encoding) throws java.lang.Exception
node
- the Node to write.output
- the Outputstream to use.encoding
- the Encoding.java.lang.Exception
- on error.public void writeDocument(org.w3c.dom.Node node, java.io.Writer writer, java.lang.String encoding) throws java.lang.Exception
node
- a Document objectwriter
- the writer to use.encoding
- the encoding format.java.lang.Exception
- on error.public org.w3c.dom.Document getCurrentDoc()
public <T> T castOrFail(java.lang.Object o, java.lang.Class<T> type, java.lang.String exceptionMsg) throws java.lang.Exception
java.lang.Exception