|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object eu.semaine.util.XMLTool
public class XMLTool
Utility methods for working wth XML documents.
Constructor Summary | |
---|---|
XMLTool()
|
Method Summary | |
---|---|
static org.w3c.dom.Element |
appendChildElement(org.w3c.dom.Node node,
java.lang.String childName)
Create a child element with the given name and append it below node. |
static org.w3c.dom.Element |
appendChildElement(org.w3c.dom.Node node,
java.lang.String childName,
java.lang.String childNamespace)
Create a child element with the given name and namespace, and append it below node. |
static org.w3c.dom.Element |
createElement(org.w3c.dom.Document doc,
java.lang.String elementName)
In the given document, create a new element of the given name, with the same namespace as the document element. |
static org.w3c.dom.Element |
createElement(org.w3c.dom.Document doc,
java.lang.String elementName,
java.lang.String namespace)
In the given document, create a new element with the given name and the given namespace. |
static javax.xml.namespace.NamespaceContext |
createNamespaceContext(java.util.Map<java.lang.String,java.lang.String> prefixes2NamespaceURIs)
Create a namespace context from the given mapping bewteen prefixes and namespace uris. |
static org.w3c.dom.traversal.NodeIterator |
createNodeIterator(org.w3c.dom.Document doc,
org.w3c.dom.Node root,
java.lang.String namespaceURI,
java.lang.String... localNames)
Create a node iterator for the current document, which will provide exactly the elements below root in the given namespace whose local names are in localNames. |
static java.lang.String |
document2String(org.w3c.dom.Document document)
Document type to String format conversion |
static java.lang.String |
getAttributeIfAvailable(org.w3c.dom.Element e,
java.lang.String attributeName)
For the given element, return the value of the given attribute if it exists, or null if it doesn't exist. |
static org.w3c.dom.Element |
getChildElementByLocalNameNS(org.w3c.dom.Node node,
java.lang.String childName,
java.lang.String childNamespace)
Get the direct child of node that is an element with the given local name and namespace. |
static org.w3c.dom.Element |
getChildElementByTagNameNS(org.w3c.dom.Node node,
java.lang.String childName,
java.lang.String childNamespace)
Get the direct child of node that is an element with the given tag name and namespace. |
static java.util.List<org.w3c.dom.Element> |
getChildrenByLocalNameNS(org.w3c.dom.Node node,
java.lang.String childName,
java.lang.String childNamespace)
Get a list of all direct children with the given local name and namespace. |
static java.util.List<org.w3c.dom.Element> |
getChildrenByTagNameNS(org.w3c.dom.Node node,
java.lang.String childName,
java.lang.String childNamespace)
Get a list of all direct children with the given tag name and namespace. |
static javax.xml.namespace.NamespaceContext |
getDefaultNamespaceContext()
Get a default namespace context. |
static boolean |
isSameNamespace(java.lang.String namespaceA,
java.lang.String namespaceB)
Determine whether the two namespaces are the same. |
static org.w3c.dom.Document |
mergeTwoXMLFiles(org.w3c.dom.Document xmlFileContent1,
org.w3c.dom.Document xmlFileContent2,
javax.xml.transform.Templates mergingStylesheet,
java.lang.String refCodeName)
Merge two XML files using XSLT |
static java.lang.String |
mergeTwoXMLFiles(java.lang.String xmlFileContent1,
java.lang.String xmlFileContent2,
java.io.InputStream xmlStyleSheet,
java.lang.String refCodeName)
Merge two XML files using XSLT |
static java.lang.String |
needAttribute(org.w3c.dom.Element e,
java.lang.String attributeName)
For the given element, return the value of the given attribute if it exists, or complain with a MessageFormatException if it doesn't exist. |
static org.w3c.dom.Element |
needChildElementByLocalNameNS(org.w3c.dom.Node node,
java.lang.String childName,
java.lang.String childNamespace)
Same as getChildElementByLocalNameNS(Node, String, String) , but
throw a MessageFormatException if there is no such child element. |
static org.w3c.dom.Element |
needChildElementByTagNameNS(org.w3c.dom.Node node,
java.lang.String childName,
java.lang.String childNamespace)
Same as getChildElementByTagNameNS(Node, String, String) , but
throw a MessageFormatException if there is no such child element. |
static org.w3c.dom.Document |
newDocument(java.lang.String rootTagname,
java.lang.String namespace)
Create a new document with the given name and namespace for the root element. |
static org.w3c.dom.Document |
newDocument(java.lang.String rootTagname,
java.lang.String namespace,
java.lang.String version)
Create a new document with the given name and namespace for the root element, and set the 'version' attribute of the root element to the given value. |
static org.w3c.dom.Document |
parse(java.io.File file)
|
static org.w3c.dom.Document |
parse(java.io.InputStream in)
|
static java.lang.String[][] |
splitXPathIntoParts(java.lang.String expr)
The given string is interpreted as a limited subset of XPath expressions and split into parts. |
static org.w3c.dom.Document |
string2Document(java.lang.String stringRepresentationOfDocument)
|
static org.w3c.dom.Document |
xpath2doc(java.lang.String xpathExpression,
java.lang.String value,
javax.xml.namespace.NamespaceContext namespaceContext,
org.w3c.dom.Document document)
Create an XML document from the given XPath expression. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public XMLTool()
Method Detail |
---|
public static org.w3c.dom.Document string2Document(java.lang.String stringRepresentationOfDocument) throws org.xml.sax.SAXException, java.io.IOException
org.xml.sax.SAXException
java.io.IOException
public static org.w3c.dom.Document parse(java.io.File file) throws org.xml.sax.SAXException, java.io.IOException
org.xml.sax.SAXException
java.io.IOException
public static org.w3c.dom.Document parse(java.io.InputStream in) throws org.xml.sax.SAXException, java.io.IOException
org.xml.sax.SAXException
java.io.IOException
public static org.w3c.dom.Document newDocument(java.lang.String rootTagname, java.lang.String namespace)
rootTagname
- namespace
- the namespace URI, e.g. http://www.w3.org/2003/04/emma
,
or null if no namespace is to be associated with the new element.
public static org.w3c.dom.Document newDocument(java.lang.String rootTagname, java.lang.String namespace, java.lang.String version)
rootTagname
- namespace
- the namespace URI, e.g. http://www.w3.org/2003/04/emma
,
or null if no namespace is to be associated with the new element.version
- a value to add to the 'version' attribute of the root element
public static org.w3c.dom.Element createElement(org.w3c.dom.Document doc, java.lang.String elementName)
doc
- a documentelementName
- the name of the new element
java.lang.NullPointerException
- if doc or elementName is null.public static org.w3c.dom.Element createElement(org.w3c.dom.Document doc, java.lang.String elementName, java.lang.String namespace)
doc
- elementName
- namespace
- the namespace URI, e.g. http://www.w3.org/2003/04/emma
,
or null if no namespace is to be associated with the new element.
java.lang.NullPointerException
- if doc or elementName is null.public static org.w3c.dom.Element appendChildElement(org.w3c.dom.Node node, java.lang.String childName)
node
- childName
-
public static org.w3c.dom.Element appendChildElement(org.w3c.dom.Node node, java.lang.String childName, java.lang.String childNamespace)
node
- childName
- childNamespace
- the namespace of the child, or null if no namespace is desired.
public static org.w3c.dom.Element getChildElementByTagNameNS(org.w3c.dom.Node node, java.lang.String childName, java.lang.String childNamespace)
node
- childName
- childNamespace
-
public static org.w3c.dom.Element getChildElementByLocalNameNS(org.w3c.dom.Node node, java.lang.String childName, java.lang.String childNamespace)
node
- childName
- the child's local name, without a namespace prefix.childNamespace
-
public static org.w3c.dom.Element needChildElementByTagNameNS(org.w3c.dom.Node node, java.lang.String childName, java.lang.String childNamespace) throws MessageFormatException
getChildElementByTagNameNS(Node, String, String)
, but
throw a MessageFormatException if there is no such child element.
node
- childName
- childNamespace
-
MessageFormatException
- if there is no such child,
i.e. when getChildElementByTagNameNS() would return null.public static org.w3c.dom.Element needChildElementByLocalNameNS(org.w3c.dom.Node node, java.lang.String childName, java.lang.String childNamespace) throws MessageFormatException
getChildElementByLocalNameNS(Node, String, String)
, but
throw a MessageFormatException if there is no such child element.
node
- childName
- childNamespace
-
MessageFormatException
- if there is no such child,
i.e. when getChildElementByTagNameNS() would return null.public static java.lang.String needAttribute(org.w3c.dom.Element e, java.lang.String attributeName) throws MessageFormatException
e
- the element whose attribute to returnattributeName
- the name of the attribute to look up.
MessageFormatException
- if the attribute doesn't exist.public static java.lang.String getAttributeIfAvailable(org.w3c.dom.Element e, java.lang.String attributeName)
e
- attributeName
-
public static java.util.List<org.w3c.dom.Element> getChildrenByTagNameNS(org.w3c.dom.Node node, java.lang.String childName, java.lang.String childNamespace)
node
- childName
- childNamespace
-
MessageFormatException
public static java.util.List<org.w3c.dom.Element> getChildrenByLocalNameNS(org.w3c.dom.Node node, java.lang.String childName, java.lang.String childNamespace)
node
- childName
- the child's local namechildNamespace
-
MessageFormatException
public static boolean isSameNamespace(java.lang.String namespaceA, java.lang.String namespaceB)
namespaceA
- a string representing a namespace, or nullnamespaceB
- a string representing a namespace, or null
public static java.lang.String mergeTwoXMLFiles(java.lang.String xmlFileContent1, java.lang.String xmlFileContent2, java.io.InputStream xmlStyleSheet, java.lang.String refCodeName) throws java.lang.Exception, java.io.FileNotFoundException
xmlFileContent1,
- first XML file contentxmlFileContent2,
- second XML file contentxmlStyleSheet,
- XSL style sheet as a inputstreamrefCodeName,
- code name used in xsl sheet to refer xmlFile2 (example: semaine.mary.intonation )
java.lang.Exception
java.io.FileNotFoundException
public static org.w3c.dom.Document mergeTwoXMLFiles(org.w3c.dom.Document xmlFileContent1, org.w3c.dom.Document xmlFileContent2, javax.xml.transform.Templates mergingStylesheet, java.lang.String refCodeName) throws java.lang.Exception, java.io.FileNotFoundException
xmlFileContent1,
- first XML file contentxmlFileContent2,
- second XML file contentmergingStylesheet,
- the XSLT style sheet merging xml2 into xml1.refCodeName,
- code name used in xsl sheet to refer xmlFile2 (example: semaine.mary.intonation )
java.lang.Exception
java.io.FileNotFoundException
public static java.lang.String document2String(org.w3c.dom.Document document) throws SystemConfigurationException
document
-
java.lang.Exception
java.io.FileNotFoundException
SystemConfigurationException
public static org.w3c.dom.traversal.NodeIterator createNodeIterator(org.w3c.dom.Document doc, org.w3c.dom.Node root, java.lang.String namespaceURI, java.lang.String... localNames)
doc
- root
- namespaceURI
- localNames
- the array of local names to be accepted.
public static org.w3c.dom.Document xpath2doc(java.lang.String xpathExpression, java.lang.String value, javax.xml.namespace.NamespaceContext namespaceContext, org.w3c.dom.Document document) throws java.lang.NullPointerException, java.lang.IllegalArgumentException
"/" ( prefix ":" ) ? localname ( "[" "@" attName "=" "'" attValue "'" "]" ) ?
The last part must be either
"/" "text()"
or
"/" "@" attributeName .
xpathExpression
- an xpath expression from which the given document can be created. must not be null.value
- the value to insert at the location identified by the xpath expression. if this is null, the empty string is added.namespaceContext
- the namespace context to use for resolving namespace prefixes.
If this is null, the namespace context returned by getDefaultNamespaceContext()
will be used.document
- if not null, the xpath expression + value pair will be added to the document.
If null, a new document will be created from the xpathExpression and value pair.
java.lang.NullPointerException
- if xpathExpression is null.
java.lang.IllegalArgumentException
- if the xpath expression is not valid, or if the xpath expression is incompatible with the given document (e.g., different root node)public static java.lang.String[][] splitXPathIntoParts(java.lang.String expr) throws java.lang.IllegalArgumentException
"/" ( prefix ":" ) ? localname ( "[" "@" attName "=" "'" attValue "'" "]" ) ?
The last part must be either
"/" "text()"
or
"/" "@" attributeName .
expr
- the string to be split as an xpath expression
java.lang.IllegalArgumentException
- if expr does not match the expected format.public static javax.xml.namespace.NamespaceContext createNamespaceContext(java.util.Map<java.lang.String,java.lang.String> prefixes2NamespaceURIs)
prefixes2NamespaceURIs
-
public static javax.xml.namespace.NamespaceContext getDefaultNamespaceContext()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |