|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.opensaml.xml.util.XMLHelper
public final class XMLHelper
A helper class for working with W3C DOM objects.
Method Summary | |
---|---|
static void |
adoptElement(org.w3c.dom.Element adoptee,
org.w3c.dom.Document adopter)
Adopts an element into a document if the child is not already in the document. |
static void |
appendChildElement(org.w3c.dom.Element parentElement,
org.w3c.dom.Element childElement)
Appends the child Element to the parent Element, adopting the child Element into the parent's Document if needed. |
static void |
appendNamespaceDeclaration(org.w3c.dom.Element domElement,
java.lang.String namespaceURI,
java.lang.String prefix)
Adds a namespace declaration (xmlns:) attribute to the given element. |
static void |
appendTextContent(org.w3c.dom.Element domElement,
java.lang.String textContent)
Creates a text node with the given content and appends it as child to the given element. |
static org.w3c.dom.Attr |
constructAttribute(org.w3c.dom.Document owningDocument,
javax.xml.namespace.QName attributeName)
Constructs an attribute owned by the given document with the given name. |
static org.w3c.dom.Attr |
constructAttribute(org.w3c.dom.Document document,
java.lang.String namespaceURI,
java.lang.String localName,
java.lang.String prefix)
Constructs an attribute owned by the given document with the given name. |
static org.w3c.dom.Element |
constructElement(org.w3c.dom.Document document,
javax.xml.namespace.QName elementName)
Constructs an element, rooted in the given document, with the given name. |
static org.w3c.dom.Element |
constructElement(org.w3c.dom.Document document,
java.lang.String namespaceURI,
java.lang.String localName,
java.lang.String prefix)
Constructs an element, rooted in the given document, with the given information. |
static javax.xml.namespace.QName |
constructQName(java.lang.String qname,
org.w3c.dom.Element owningElement)
Constructs a QName from a string (attribute element content) value. |
static javax.xml.namespace.QName |
constructQName(java.lang.String namespaceURI,
java.lang.String localName,
java.lang.String prefix)
Constructs a QName. |
static javax.xml.namespace.QName |
constructQName(java.lang.String qname,
XMLObject owningObject)
Constructs a QName from a string (attribute or element content) value. |
static long |
durationToLong(java.lang.String duration)
Converts a lexical duration, as defined by XML Schema 1.0, into milliseconds. |
static java.lang.Boolean |
getAttributeValueAsBoolean(org.w3c.dom.Attr attribute)
Parses the attribute's value. |
static java.util.List<java.lang.String> |
getAttributeValueAsList(org.w3c.dom.Attr attribute)
Gets the value of a list-type attribute as a list. |
static javax.xml.namespace.QName |
getAttributeValueAsQName(org.w3c.dom.Attr attribute)
Constructs a QName from an attributes value. |
static java.util.Map<javax.xml.namespace.QName,java.util.List<org.w3c.dom.Element>> |
getChildElements(org.w3c.dom.Element root)
Gets the child elements of the given element in a single iteration. |
static java.util.List<org.w3c.dom.Element> |
getChildElementsByTagName(org.w3c.dom.Element root,
java.lang.String localName)
Gets the child nodes with the given local tag name. |
static java.util.List<org.w3c.dom.Element> |
getChildElementsByTagNameNS(org.w3c.dom.Element root,
java.lang.String namespaceURI,
java.lang.String localName)
Gets the child nodes with the given namespace qualified tag name. |
static javax.xml.datatype.DatatypeFactory |
getDataTypeFactory()
Gets a static instance of a JAXP DatatypeFactory. |
static org.w3c.dom.Element |
getElementAncestor(org.w3c.dom.Node currentNode)
Gets the ancestor element node to the given node. |
static java.util.List<java.lang.String> |
getElementContentAsList(org.w3c.dom.Element element)
Gets the value of a list-type element as a list. |
static javax.xml.namespace.QName |
getElementContentAsQName(org.w3c.dom.Element element)
Constructs a QName from an element's adjacent Text child nodes. |
static org.w3c.dom.Element |
getFirstChildElement(org.w3c.dom.Node n)
Gets the first child Element of the node, skipping any Text nodes such as whitespace. |
static org.w3c.dom.Attr |
getIdAttribute(org.w3c.dom.Element domElement)
Gets the ID attribute of a DOM element. |
static java.util.Locale |
getLanguage(org.w3c.dom.Element element)
Gets the lcoale currently active for the element. |
static org.w3c.dom.Element |
getNextSiblingElement(org.w3c.dom.Node n)
Gets the next sibling Element of the node, skipping any Text nodes such as whitespace. |
static javax.xml.namespace.QName |
getNodeQName(org.w3c.dom.Node domNode)
Gets the QName for the given DOM node. |
static javax.xml.namespace.QName |
getXSIType(org.w3c.dom.Element e)
Gets the XSI type for a given element if it has one. |
static boolean |
hasXSIType(org.w3c.dom.Element e)
Checks if the given element has an xsi:type defined for it. |
static boolean |
isElementNamed(org.w3c.dom.Element e,
java.lang.String ns,
java.lang.String localName)
Shortcut for checking a DOM element node's namespace and local name. |
static java.lang.String |
longToDuration(long duration)
Converts a duration in milliseconds to a lexical duration, as defined by XML Schema 1.0. |
static java.lang.String |
lookupNamespaceURI(org.w3c.dom.Element startingElement,
org.w3c.dom.Element stopingElement,
java.lang.String prefix)
Looks up the namespace URI associated with the given prefix starting at the given element. |
static java.lang.String |
lookupNamespaceURI(org.w3c.dom.Element startingElement,
java.lang.String prefix)
Looks up the namespace URI associated with the given prefix starting at the given element. |
static java.lang.String |
lookupPrefix(org.w3c.dom.Element startingElement,
org.w3c.dom.Element stopingElement,
java.lang.String namespaceURI)
Looks up the namespace prefix associated with the given URI starting at the given element. |
static java.lang.String |
lookupPrefix(org.w3c.dom.Element startingElement,
java.lang.String namespaceURI)
Looks up the namespace prefix associated with the given URI starting at the given element. |
static java.lang.String |
nodeToString(org.w3c.dom.Node node)
Converts a Node into a String using the DOM, level 3, Load/Save serializer. |
static java.lang.String |
prettyPrintXML(org.w3c.dom.Node node)
Pretty prints the XML node. |
static java.lang.String |
qnameToContentString(javax.xml.namespace.QName qname)
Converts a QName into a string that can be used for attribute values or element content. |
static void |
rootNamespaces(org.w3c.dom.Element domElement)
Ensures that all the visibly used namespaces referenced by the given Element or its descendants are declared by the given Element or one of its descendants. |
static void |
writeNode(org.w3c.dom.Node node,
java.io.Writer output)
Writes a Node out to a Writer using the DOM, level 3, Load/Save serializer. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static javax.xml.datatype.DatatypeFactory getDataTypeFactory()
public static boolean hasXSIType(org.w3c.dom.Element e)
e
- the DOM element
public static javax.xml.namespace.QName getXSIType(org.w3c.dom.Element e)
e
- the element
public static org.w3c.dom.Attr getIdAttribute(org.w3c.dom.Element domElement)
domElement
- the DOM element
public static javax.xml.namespace.QName getNodeQName(org.w3c.dom.Node domNode)
domNode
- the DOM node
public static java.util.Locale getLanguage(org.w3c.dom.Element element)
element
- element to retrieve local information for
public static org.w3c.dom.Attr constructAttribute(org.w3c.dom.Document owningDocument, javax.xml.namespace.QName attributeName)
owningDocument
- the owning documentattributeName
- the name of that attribute
public static org.w3c.dom.Attr constructAttribute(org.w3c.dom.Document document, java.lang.String namespaceURI, java.lang.String localName, java.lang.String prefix)
document
- the owning documentnamespaceURI
- the URI for the namespace the attribute is inlocalName
- the local nameprefix
- the prefix of the namespace that attribute is in
public static javax.xml.namespace.QName getAttributeValueAsQName(org.w3c.dom.Attr attribute)
attribute
- the attribute with a QName value
public static java.lang.Boolean getAttributeValueAsBoolean(org.w3c.dom.Attr attribute)
attribute
- attribute whose value will be converted to a boolean
public static java.util.List<java.lang.String> getAttributeValueAsList(org.w3c.dom.Attr attribute)
attribute
- attribute whose value will be turned into a list
public static javax.xml.namespace.QName getElementContentAsQName(org.w3c.dom.Element element)
element
- the element with a QName value
public static java.util.List<java.lang.String> getElementContentAsList(org.w3c.dom.Element element)
element
- element whose value will be turned into a list
public static javax.xml.namespace.QName constructQName(java.lang.String namespaceURI, java.lang.String localName, java.lang.String prefix)
namespaceURI
- the namespace of the QNamelocalName
- the local name of the QNameprefix
- the prefix of the QName, may be null
public static javax.xml.namespace.QName constructQName(java.lang.String qname, XMLObject owningObject)
qname
- the QName stringowningObject
- XMLObject, with cached DOM, owning the QName
public static javax.xml.namespace.QName constructQName(java.lang.String qname, org.w3c.dom.Element owningElement)
qname
- the QName stringowningElement
- parent DOM element of the Node which contains the QName value
public static org.w3c.dom.Element constructElement(org.w3c.dom.Document document, javax.xml.namespace.QName elementName)
document
- the document containing the elementelementName
- the name of the element, must contain a local name, may contain a namespace URI and prefix
public static org.w3c.dom.Element constructElement(org.w3c.dom.Document document, java.lang.String namespaceURI, java.lang.String localName, java.lang.String prefix)
document
- the document containing the elementnamespaceURI
- the URI of the namespace the element is inlocalName
- the element's local nameprefix
- the prefix of the namespace the element is in
public static void appendChildElement(org.w3c.dom.Element parentElement, org.w3c.dom.Element childElement)
parentElement
- the parent ElementchildElement
- the child Elementpublic static void adoptElement(org.w3c.dom.Element adoptee, org.w3c.dom.Document adopter)
adoptee
- the element to be adoptedadopter
- the document into which the element is adoptedpublic static void appendTextContent(org.w3c.dom.Element domElement, java.lang.String textContent)
domElement
- the element to recieve the text nodetextContent
- the content for the text nodepublic static void appendNamespaceDeclaration(org.w3c.dom.Element domElement, java.lang.String namespaceURI, java.lang.String prefix)
domElement
- the element to add the attribute tonamespaceURI
- the URI of the namespaceprefix
- the prefix for the namespacepublic static java.lang.String lookupNamespaceURI(org.w3c.dom.Element startingElement, java.lang.String prefix)
Node.lookupNamespaceURI(java.lang.String)
in that it only those namespaces declared by an xmlns
attribute are inspected. The Node method also checks the namespace a particular node was created in by way of a
call like Document.createElementNS(java.lang.String, java.lang.String)
even if the resulting element
doesn't have an namespace delcaration attribute.
startingElement
- the starting elementprefix
- the prefix to look up
public static java.lang.String lookupNamespaceURI(org.w3c.dom.Element startingElement, org.w3c.dom.Element stopingElement, java.lang.String prefix)
Node.lookupNamespaceURI(java.lang.String)
in that it only those namespaces declared by an xmlns
attribute are inspected. The Node method also checks the namespace a particular node was created in by way of a
call like Document.createElementNS(java.lang.String, java.lang.String)
even if the resulting element
doesn't have an namespace delcaration attribute.
startingElement
- the starting elementstopingElement
- the ancestor of the starting element that serves as the upper-bound for the searchprefix
- the prefix to look up
public static java.lang.String lookupPrefix(org.w3c.dom.Element startingElement, java.lang.String namespaceURI)
Node.lookupPrefix(java.lang.String)
in that it only those namespaces declared by an xmlns
attribute are inspected. The Node method also checks the namespace a particular node was created in by way of a
call like Document.createElementNS(java.lang.String, java.lang.String)
even if the resulting element
doesn't have an namespace delcaration attribute.
startingElement
- the starting elementnamespaceURI
- the uri to look up
public static java.lang.String lookupPrefix(org.w3c.dom.Element startingElement, org.w3c.dom.Element stopingElement, java.lang.String namespaceURI)
Node.lookupPrefix(java.lang.String)
in that it only those namespaces declared by an xmlns
attribute are inspected. The Node method also checks the namespace a particular node was created in by way of a
call like Document.createElementNS(java.lang.String, java.lang.String)
even if the resulting element
doesn't have an namespace delcaration attribute.
startingElement
- the starting elementstopingElement
- the ancestor of the starting element that serves as the upper-bound for the searchnamespaceURI
- the uri to look up
public static java.util.List<org.w3c.dom.Element> getChildElementsByTagNameNS(org.w3c.dom.Element root, java.lang.String namespaceURI, java.lang.String localName)
getChildElements(Element)
.
root
- element to retrieve the children fromnamespaceURI
- namespace URI of the child elementlocalName
- local, tag, name of the child element
public static java.util.List<org.w3c.dom.Element> getChildElementsByTagName(org.w3c.dom.Element root, java.lang.String localName)
getChildElements(Element)
.
root
- element to retrieve the children fromlocalName
- local, tag, name of the child element
public static java.util.Map<javax.xml.namespace.QName,java.util.List<org.w3c.dom.Element>> getChildElements(org.w3c.dom.Element root)
root
- element to get the child elements of
public static org.w3c.dom.Element getElementAncestor(org.w3c.dom.Node currentNode)
currentNode
- the node to retrive the ancestor for
public static java.lang.String nodeToString(org.w3c.dom.Node node)
node
- the node to be written to a string
public static java.lang.String prettyPrintXML(org.w3c.dom.Node node)
node
- xml node to print
public static void writeNode(org.w3c.dom.Node node, java.io.Writer output)
node
- the node to write outoutput
- the writer to write the XML topublic static java.lang.String qnameToContentString(javax.xml.namespace.QName qname)
qname
- the QName to convert to a string
public static void rootNamespaces(org.w3c.dom.Element domElement) throws XMLParserException
domElement
- the element to act as the root of the namespace declarations
XMLParserException
- thrown if a namespace prefix is encountered that can't be resolved to a namespace URIpublic static boolean isElementNamed(org.w3c.dom.Element e, java.lang.String ns, java.lang.String localName)
e
- An element to compare againstns
- An XML namespace to comparelocalName
- A local name to compare
public static org.w3c.dom.Element getFirstChildElement(org.w3c.dom.Node n)
n
- The parent in which to search for children
public static org.w3c.dom.Element getNextSiblingElement(org.w3c.dom.Node n)
n
- The sibling to start with
public static long durationToLong(java.lang.String duration)
duration
- lexical duration representation
public static java.lang.String longToDuration(long duration)
duration
- the duration
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |