public class JaxpHelper
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static org.apache.log4j.Logger |
_logger |
static java.lang.String |
INDENT |
Modifier | Constructor and Description |
---|---|
private |
JaxpHelper() |
Modifier and Type | Method and Description |
---|---|
static org.w3c.dom.Element |
addCDATA(org.w3c.dom.Element el,
java.lang.String cdata,
org.w3c.dom.Document document)
Adds CDATA section to
el and returns modified el . |
static void |
addNamespace(org.w3c.dom.Document dom,
XmlNs ns)
Adds the namespace binding definition to DOM
dom (to define multiple namespace
bindings on the root element). |
static org.w3c.dom.Element |
addQSubElement(org.w3c.dom.Element el,
java.lang.String qname,
org.w3c.dom.Document document)
Adds sub-element to
el and returns modified el . |
static XmlString |
asPrettyXml(org.w3c.dom.Node documentOrElement,
java.io.File xmlFile)
Returns
documentOrElement as pretty-print XML string and saves it to
xmlFile if not null. |
static XmlString |
asPrettyXml(XmlString xmlText,
java.io.File xmlFile)
Returns
xmlText as pretty-print string and saves to xmlFile if not
null. |
static XmlString |
asXml(org.w3c.dom.Node documentOrElement,
java.io.File xmlFile)
Returns
documentOrElement as XML string and saves it to xmlFile if
not null. |
static javax.xml.xpath.XPathExpression |
compileXpath(java.lang.String xpathExpression,
XmlNs... namespaces)
Returns compiled xpath expression that recognises all
namespaces . |
static org.w3c.dom.Document |
createDocumentWithRoot(java.lang.String comment,
java.lang.String rootName,
XmlNs ns)
Returns a document with
rootName element. |
static org.w3c.dom.Element |
createQRoot(java.lang.String qname,
org.w3c.dom.Document document)
Creates root element, adds it to the document and returns that new root element.
|
static org.w3c.dom.Element |
createQSubElement(org.w3c.dom.Element el,
java.lang.String qname,
org.w3c.dom.Document document)
Creates sub-element, adds it to
el and returns that new sub-element. |
static javax.xml.xpath.XPath |
createXpath(XmlNs... namespaces)
Returns the xpath instance that recognises all
namespaces . |
(package private) static XmlString |
embedIntoRoot(XmlString xmlSnippet,
java.lang.String rootName,
XmlNs ns)
(useful for testing, to set anything as an XML string) Returns
xmlSnippet
embedded into root for the given namespace binding. |
static java.util.List<org.w3c.dom.Attr> |
getAttributes(org.w3c.dom.Element el)
Returns all attributes of
el , potentially empty list. |
private static java.util.List<org.w3c.dom.Attr> |
getAttributes(org.w3c.dom.Element el,
java.lang.String name) |
private static javax.xml.transform.Transformer |
getConfiguredTransformer(java.lang.String encoding,
java.lang.String indentAmount,
java.lang.String systemValue) |
static org.w3c.dom.Element |
getFirstNamedSubElement(org.w3c.dom.Element el,
java.lang.String name)
Returns first element under
el with the name if found, null
otherwise. |
static org.w3c.dom.Attr |
getNamedAttribute(org.w3c.dom.Element el,
java.lang.String name)
Returns attribute of
el with the name if found, null otherwise. |
static java.util.List<org.w3c.dom.Element> |
getNamedSubElements(org.w3c.dom.Element el,
java.lang.String name)
Returns elements under
el with the name if found, empty list
otherwise. |
static java.util.List<org.w3c.dom.Element> |
getSubElements(org.w3c.dom.Element el)
Returns all elements under
el , potentially empty list. |
private static java.util.List<org.w3c.dom.Element> |
getSubElements(org.w3c.dom.Element el,
java.lang.String name,
boolean single) |
private static XmlString |
getXml(org.w3c.dom.Node documentOrElement,
XmlString xmlText,
java.io.File xmlFile,
java.lang.String indentAmount) |
static org.w3c.dom.Document |
parseAsDocument(XmlString xmlText)
Parses
xmlText and returns DOM document containing it on success, null on
failure or if xmlText is null. |
static org.w3c.dom.DocumentFragment |
parseAsFragment(XmlString xmlText)
Parses
xmlText and returns DOM document fragment on success, null on failure or
if xmlText is null. |
static java.util.List<org.w3c.dom.Element> |
selectElements(java.lang.String xpathExpression,
java.lang.Object ctx,
XmlNs... namespaces) |
static org.w3c.dom.Node |
selectNode(java.lang.String xpathExpression,
java.lang.Object ctx,
XmlNs[] namespaces) |
static java.util.List<org.w3c.dom.Node> |
selectNodes(java.lang.String xpathExpression,
java.lang.Object ctx,
XmlNs... namespaces) |
private static final org.apache.log4j.Logger _logger
public static final java.lang.String INDENT
public static org.w3c.dom.Document createDocumentWithRoot(java.lang.String comment, java.lang.String rootName, XmlNs ns)
rootName
element. If ns
is not null, the
root element is qualified with the namespace, and specifies the binding prefix/URI for that
namespace.comment
- (potentially null or empty) document comment.rootName
- non-null, non-empty name of the root element.ns
- (potentially null) namespace definition.public static void addNamespace(org.w3c.dom.Document dom, XmlNs ns)
dom
(to define multiple namespace
bindings on the root element).dom
- non-null element to which to add the namespace binding.ns
- non-null namespace.static XmlString embedIntoRoot(XmlString xmlSnippet, java.lang.String rootName, XmlNs ns)
xmlSnippet
embedded into root
for the given namespace binding. If both
rootName
and ns
are null or empty, does not bind any namespace.public static org.w3c.dom.Element createQRoot(java.lang.String qname, org.w3c.dom.Document document)
public static org.w3c.dom.Element createQSubElement(org.w3c.dom.Element el, java.lang.String qname, org.w3c.dom.Document document)
el
and returns that new sub-element.public static org.w3c.dom.Element addQSubElement(org.w3c.dom.Element el, java.lang.String qname, org.w3c.dom.Document document)
el
and returns modified el
.public static org.w3c.dom.Element addCDATA(org.w3c.dom.Element el, java.lang.String cdata, org.w3c.dom.Document document)
el
and returns modified el
.public static javax.xml.xpath.XPath createXpath(XmlNs... namespaces)
namespaces
.public static javax.xml.xpath.XPathExpression compileXpath(java.lang.String xpathExpression, XmlNs... namespaces)
namespaces
.public static org.w3c.dom.Node selectNode(java.lang.String xpathExpression, java.lang.Object ctx, XmlNs[] namespaces)
public static java.util.List<org.w3c.dom.Node> selectNodes(java.lang.String xpathExpression, java.lang.Object ctx, XmlNs... namespaces)
public static java.util.List<org.w3c.dom.Element> selectElements(java.lang.String xpathExpression, java.lang.Object ctx, XmlNs... namespaces)
public static org.w3c.dom.Document parseAsDocument(XmlString xmlText)
xmlText
and returns DOM document containing it on success, null on
failure or if xmlText
is null. Use this method when you require fully validated
document.public static org.w3c.dom.DocumentFragment parseAsFragment(XmlString xmlText)
xmlText
and returns DOM document fragment on success, null on failure or
if xmlText
is null. Use this method when you require fully validated document
fragment.public static XmlString asPrettyXml(org.w3c.dom.Node documentOrElement, java.io.File xmlFile)
documentOrElement
as pretty-print XML string and saves it to
xmlFile
if not null.public static XmlString asXml(org.w3c.dom.Node documentOrElement, java.io.File xmlFile)
documentOrElement
as XML string and saves it to xmlFile
if
not null.public static XmlString asPrettyXml(XmlString xmlText, java.io.File xmlFile)
xmlText
as pretty-print string and saves to xmlFile
if not
null.private static XmlString getXml(org.w3c.dom.Node documentOrElement, XmlString xmlText, java.io.File xmlFile, java.lang.String indentAmount)
private static javax.xml.transform.Transformer getConfiguredTransformer(java.lang.String encoding, java.lang.String indentAmount, java.lang.String systemValue) throws javax.xml.transform.TransformerConfigurationException, javax.xml.transform.TransformerFactoryConfigurationError
javax.xml.transform.TransformerConfigurationException
javax.xml.transform.TransformerFactoryConfigurationError
public static java.util.List<org.w3c.dom.Element> getSubElements(org.w3c.dom.Element el)
el
, potentially empty list.public static java.util.List<org.w3c.dom.Element> getNamedSubElements(org.w3c.dom.Element el, java.lang.String name)
el
with the name
if found, empty list
otherwise.public static org.w3c.dom.Element getFirstNamedSubElement(org.w3c.dom.Element el, java.lang.String name)
el
with the name
if found, null
otherwise.private static java.util.List<org.w3c.dom.Element> getSubElements(org.w3c.dom.Element el, java.lang.String name, boolean single)
public static java.util.List<org.w3c.dom.Attr> getAttributes(org.w3c.dom.Element el)
el
, potentially empty list.public static org.w3c.dom.Attr getNamedAttribute(org.w3c.dom.Element el, java.lang.String name)
el
with the name
if found, null otherwise.private static java.util.List<org.w3c.dom.Attr> getAttributes(org.w3c.dom.Element el, java.lang.String name)
Copyright 2009-2015 Tatjana (Tanja) Kostic