|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.osesb.utilities.xml.DOMUtils
public class DOMUtils
Utilities for parsing with DOM.
| Constructor Summary | |
|---|---|
DOMUtils()
|
|
| Method Summary | |
|---|---|
static org.w3c.dom.Element |
addChildElement(org.w3c.dom.Element parentElement,
java.lang.String elementTagName,
java.lang.String elementValue)
Adds a new Element to the end of the list of children of the parentElement. |
static org.w3c.dom.Attr |
createAttribute(java.lang.String name,
java.lang.String value)
Creates and returns a new, unattached Attribute with the given name and optional value. |
static org.w3c.dom.Attr |
createAttribute(java.lang.String namespaceURI,
java.lang.String name,
java.lang.String value)
Creates and returns a new, unattached Attribute with the given name, optional namespace, and optional value. |
static org.w3c.dom.Element |
createElement(java.lang.String name)
Creates and returns an empty, unattached Element with the given name. |
static org.w3c.dom.Element |
createElement(java.lang.String namespaceURI,
java.lang.String name)
Creates and returns an empty, unattached Element with the given namespaceURI and name. |
static org.w3c.dom.Element |
getChildElement(org.w3c.dom.Document document,
java.lang.String elementName)
Returns the first occurence of the XML element with elementName that is an immediate child of Document. |
static org.w3c.dom.Element |
getChildElement(org.w3c.dom.Element parentElement)
Returns the first immediate child Element of the parentElement. |
static org.w3c.dom.Element |
getChildElement(org.w3c.dom.Element parentElement,
java.lang.String elementName)
Returns the first occurence of the XML element with elementName that is an immediate child of parentElement. |
static org.w3c.dom.Element |
getChildElement(org.w3c.dom.Element parentElement,
java.lang.String elementName,
java.lang.String attributeName,
java.lang.String attributeValue)
Returns the first occurence of a XML element, with a specified attribute, that is an immediate child of parentElement. |
static java.util.List |
getChildElementsAsList(org.w3c.dom.Element element)
Returns all the immediate child Elements of an Element as a List of DOM Elements. |
static java.util.List |
getChildElementsAsList(org.w3c.dom.Element element,
java.lang.String elementTagName)
Returns all the named immediate child Elements of an Element as a List of DOM Elements. |
static java.util.Map |
getChildElementsAsMap(org.w3c.dom.Element element)
Returns all the immediate child Elements of an Element, including attributes, as a Map of DOM EElements, keyed by the Element's tag name. |
static org.w3c.dom.Document |
getDocument(org.w3c.dom.Node node)
Returns the Document node that contains node. |
static org.w3c.dom.Element |
getElement(org.w3c.dom.Document document,
java.lang.String elementName)
Returns the first occurence of the named XML element that is encountered in a preorder traversal of parentElement. |
static org.w3c.dom.Element |
getElement(org.w3c.dom.Document document,
java.lang.String elementName,
int index)
Returns the n'th occurence of a named XML element that is encountered in a preorder traversal of parentElement. |
static org.w3c.dom.Element |
getElement(org.w3c.dom.Element parentElement,
java.lang.String elementName)
Returns the first occurence of the named XML element with elementName that is encountered in a preorder traversal of parentElement. |
static org.w3c.dom.Element |
getElement(org.w3c.dom.Element parentElement,
java.lang.String elementName,
int index)
Returns the n'th occurence of the XML element with elementName that is encountered in a preorder traversal of parentElement. |
static org.w3c.dom.Element |
getElement(org.w3c.dom.Element parentElement,
java.lang.String elementName,
java.lang.String attributeName,
java.lang.String attributeValue)
Returns the first occurence of a XML element, with a specified attribute, that is encountered in a preorder traversal of parentElement. |
static org.w3c.dom.Attr[] |
getElementAttributes(org.w3c.dom.Element element)
Returns attributes of an Element as an array of org.w3c.dom.Attr |
static java.util.Properties |
getElementAttributesAsProperties(org.w3c.dom.Element element)
Returns the attributes of an Element as Properties |
static java.lang.String |
getElementAttributeValue(org.w3c.dom.Element element,
java.lang.String attributeName)
Returns the value for an Attribute of an Element. |
static java.lang.String |
getElementValue(org.w3c.dom.Element element)
Returns the text value of a XML element. |
static java.lang.String |
getNodeValue(org.w3c.dom.Node node)
Returns the text value of a XML Node. |
static boolean |
isElementEmpty(org.w3c.dom.Element element)
Tests if a Element is empty. |
static void |
main(java.lang.String[] args)
Main method for testing and sandboxing. |
static org.w3c.dom.Document |
parseDOM(java.lang.String xmlText)
Parse a document using a JAXP-compliant DOM parser and JAXP parser default properties. |
static org.w3c.dom.Document |
parseDOM(java.lang.String xmlText,
boolean namespaceAware)
Parse a document using a JAXP-compliant DOM parser, specifying the namespaceAware attribute for the parser. |
static org.w3c.dom.Document |
parseDOM(java.lang.String xmlText,
boolean namespaceAware,
boolean validating,
java.lang.String schemaLanguage,
java.io.File[] schemaSource,
org.xml.sax.ErrorHandler errorHandler)
Parse a document using a JAXP-compliant DOM parser specifying factory and parser attributes and passing a File[] of schemaSource(s). |
static org.w3c.dom.Document |
parseDOM(java.lang.String xmlText,
boolean namespaceAware,
boolean validating,
java.lang.String schemaLanguage,
java.lang.Object schemaSource,
org.xml.sax.ErrorHandler errorHandler)
Parse a document using a JAXP-compliant DOM parser specifying factory and parser attributes and passing a single schema source. |
static org.w3c.dom.Document |
parseDOM(java.lang.String xmlText,
org.xml.sax.EntityResolver entityResolver)
Parse a document using a JAXP-compliant DOM parser using an EntityResolver to handle external entities. |
static org.w3c.dom.Document |
parseDOM(java.lang.String xmlText,
org.xml.sax.EntityResolver entityResolver,
boolean namespaceAware,
boolean validating,
java.lang.String schemaLanguage,
org.xml.sax.ErrorHandler errorHandler)
Parse a document using a JAXP-compliant DOM parser specifying common factory and parser attributes and passing a File[] of schemaSource(s). |
static org.w3c.dom.Document |
parseDOM(java.lang.String xmlText,
java.io.File[] schemaSource)
Parse a document using a JAXP-compliant DOM parser specifying factory and parser attributes and passing a File[] of schemaSource(s). |
static org.w3c.dom.Document |
parseDOM(java.lang.String xmlText,
java.lang.Object schemaSource)
Parse a document using a JAXP-compliant DOM parser with namespaceaware=true, validating=true, schemaLanguage = XML Schema, and passing a schema source. |
static org.w3c.dom.Document |
parseDOM(java.lang.String xmlText,
javax.xml.validation.Schema schema)
Parse a document using a JAXP-compliant DOM parser and a compiled Schema |
static org.w3c.dom.Document |
parseDOM(java.lang.String xmlText,
javax.xml.validation.Schema schema,
org.xml.sax.ErrorHandler errorHandler)
Parse a document using a JAXP-compliant DOM parser with validation against a compiled Schema |
static org.w3c.dom.Element |
removeElement(org.w3c.dom.Element element)
Removes the Element from the DOM tree. |
static void |
setDocumentBuilderAttributes(javax.xml.parsers.DocumentBuilderFactory dbf,
boolean namespaceAware,
boolean validating,
java.lang.String schemaLanguage)
Set DocumentBuilderFactory attributes |
static void |
setElementValue(org.w3c.dom.Element element,
java.lang.String value)
Sets the Svalue of a XML element. |
static void |
setExternalSchemaLocation(javax.xml.parsers.DocumentBuilderFactory dbf,
java.io.File[] schemaSource,
java.lang.String xmlText)
This is method sets the http://apache.org/xml/properties/schema/external-schemaLocation or http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation for a Xerces parser using schemaSources specified as a java.io.File[]. |
static void |
setNodeValue(org.w3c.dom.Node node,
java.lang.String value)
Sets the text value of a XML Node. |
static boolean |
validSchemaSource(java.lang.Object schemaSource)
Validates the schema source for a DocumentBuilderFactory. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public DOMUtils()
| Method Detail |
|---|
public static org.w3c.dom.Document parseDOM(java.lang.String xmlText)
throws javax.xml.parsers.ParserConfigurationException,
java.io.IOException,
org.xml.sax.SAXException,
java.lang.Exception
xmlText - The XML String to parse.
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
java.io.IOException
java.lang.Exception
public static org.w3c.dom.Document parseDOM(java.lang.String xmlText,
boolean namespaceAware)
throws org.xml.sax.SAXException,
javax.xml.parsers.ParserConfigurationException,
java.io.IOException,
java.lang.Exception
xmlText - The XML String to parse
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
java.io.IOException
java.lang.Exception
public static org.w3c.dom.Document parseDOM(java.lang.String xmlText,
java.lang.Object schemaSource)
throws org.xml.sax.SAXException,
javax.xml.parsers.ParserConfigurationException,
java.io.IOException,
java.lang.Exception
xmlText - The XML String to parseschemaSource - any JAXP_SCHEMA_SOURCE
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
java.io.IOException
java.lang.Exception
public static org.w3c.dom.Document parseDOM(java.lang.String xmlText,
java.io.File[] schemaSource)
throws org.xml.sax.SAXException,
javax.xml.parsers.ParserConfigurationException,
java.io.IOException,
java.lang.Exception
xmlText - The XML String to parseschemaSource - File[] of schema sources
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
java.io.IOException
java.lang.Exception
public static org.w3c.dom.Document parseDOM(java.lang.String xmlText,
boolean namespaceAware,
boolean validating,
java.lang.String schemaLanguage,
java.lang.Object schemaSource,
org.xml.sax.ErrorHandler errorHandler)
throws org.xml.sax.SAXException,
javax.xml.parsers.ParserConfigurationException,
java.io.IOException,
java.lang.Exception
xmlText - xml String to parsenamespaceAware - If true then DocumentBuilderFactory is configured to produce parsers which are namespace awarevalidating - If true then DocumentBuilderFactory is configured to produce parsers which validate the XML content during parseschemaLanguage - XMLParserConstants.SCHEMA_LANGUAGE_XSD or XMLParserConstants.SCHEMA_LANGUAGE_DTDschemaSource - Any XMLParserConstants.JAXP_SCHEMA_SOURCEerrorHandler - An error handler
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
java.io.IOException
java.lang.Exception
public static org.w3c.dom.Document parseDOM(java.lang.String xmlText,
boolean namespaceAware,
boolean validating,
java.lang.String schemaLanguage,
java.io.File[] schemaSource,
org.xml.sax.ErrorHandler errorHandler)
throws org.xml.sax.SAXException,
javax.xml.parsers.ParserConfigurationException,
java.io.IOException,
java.lang.Exception
xmlText - xml String to parsenamespaceAware - If true then DocumentBuilderFactory is configured to produce parsers which are namespace awarevalidating - If true then DocumentBuilderFactory is configured to produce parsers which validate the XML content during parseschemaLanguage - XMLParserConstants.SCHEMA_LANGUAGE_XSD or XMLParserConstants.SCHEMA_LANGUAGE_DTDschemaSource - a File[] of schema sourceserrorHandler - An error handler
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
java.io.IOException
java.lang.Exception
public static org.w3c.dom.Document parseDOM(java.lang.String xmlText,
org.xml.sax.EntityResolver entityResolver)
throws org.xml.sax.SAXException,
javax.xml.parsers.ParserConfigurationException,
java.io.IOException,
java.lang.Exception
xmlText - xml String to parseentityResolver - Implements org.xml.sax.EntityResolver.
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
java.io.IOException
java.lang.Exception
public static org.w3c.dom.Document parseDOM(java.lang.String xmlText,
org.xml.sax.EntityResolver entityResolver,
boolean namespaceAware,
boolean validating,
java.lang.String schemaLanguage,
org.xml.sax.ErrorHandler errorHandler)
throws org.xml.sax.SAXException,
javax.xml.parsers.ParserConfigurationException,
java.io.IOException,
java.lang.Exception
xmlText - xml String to parseentityResolver - Implements org.xml.sax.EntityResolver.namespaceAware - If true then DocumentBuilderFactory is configured to produce parsers which are namespace awarevalidating - If true then DocumentBuilderFactory is configured to produce parsers which validate the XML content during parseschemaLanguage - XMLParserConstants.SCHEMA_LANGUAGE_XSD or XMLParserConstants.SCHEMA_LANGUAGE_DTDerrorHandler - An error handler
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
java.io.IOException
java.lang.Exception
public static org.w3c.dom.Document parseDOM(java.lang.String xmlText,
javax.xml.validation.Schema schema)
throws org.xml.sax.SAXException,
javax.xml.parsers.ParserConfigurationException,
java.io.IOException,
java.lang.Exception
xmlText - The XML String to parseschema - a jaxp v1.3 compiled schema
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
java.io.IOException
java.lang.Exception
public static org.w3c.dom.Document parseDOM(java.lang.String xmlText,
javax.xml.validation.Schema schema,
org.xml.sax.ErrorHandler errorHandler)
throws org.xml.sax.SAXException,
javax.xml.parsers.ParserConfigurationException,
java.io.IOException,
java.lang.Exception
xmlText - The XML String to parseschema - a jaxp v1.3 compiled schemaerrorHandler - An error handler
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
java.io.IOException
java.lang.Exceptionpublic static org.w3c.dom.Document getDocument(org.w3c.dom.Node node)
public static void setDocumentBuilderAttributes(javax.xml.parsers.DocumentBuilderFactory dbf,
boolean namespaceAware,
boolean validating,
java.lang.String schemaLanguage)
throws java.lang.Exception
namespaceAware - If true then DocumentBuilderFactory is configured to produce parsers which are namespace awarevalidating - If true then DocumentBuilderFactory is configured to produce parsers which validate the XML content during parseschemaLanguage - XMLParserConstants.SCHEMA_LANGUAGE_XSD or XMLParserConstants.SCHEMA_LANGUAGE_DTD
java.lang.Exceptionpublic static boolean validSchemaSource(java.lang.Object schemaSource)
schemaSource - The JAXP_SCHEMA_SOURCE.
public static void setExternalSchemaLocation(javax.xml.parsers.DocumentBuilderFactory dbf,
java.io.File[] schemaSource,
java.lang.String xmlText)
dbf - The DocumentBuilderFactory to set the schema locations for.schemaSource - an array of java.io.File.xmlText - The XML text that is being parsed/validated.
public static org.w3c.dom.Element addChildElement(org.w3c.dom.Element parentElement,
java.lang.String elementTagName,
java.lang.String elementValue)
throws java.lang.Exception
parentElement - The Element to add a new child Element to.elementTagName - The tag name for the new Element.elementValue - The value for the new Element.
java.lang.Exception - if the Element could not be added.
public static org.w3c.dom.Element removeElement(org.w3c.dom.Element element)
throws java.lang.Exception
element - The Element to remove.
java.lang.Exception - if the Element could not be removed.
public static org.w3c.dom.Element getChildElement(org.w3c.dom.Document document,
java.lang.String elementName)
document - The DocumentelementName - The Element name to look for, including
the namespace prefix, if any.
public static org.w3c.dom.Element getChildElement(org.w3c.dom.Element parentElement)
parentElement - The parent Element
public static org.w3c.dom.Element getChildElement(org.w3c.dom.Element parentElement,
java.lang.String elementName)
parentElement - The parent ElementelementName - The Element name to look for, including
the namespace prefix, if any.
public static org.w3c.dom.Element getChildElement(org.w3c.dom.Element parentElement,
java.lang.String elementName,
java.lang.String attributeName,
java.lang.String attributeValue)
parentElement - The parent ElementelementName - The Element name to look for, including
the namespace prefix, if any.attributeName - The Attribute name to look for.attributeValue - The Attribute value to look for.
public static java.util.Map getChildElementsAsMap(org.w3c.dom.Element element)
element - The Element to get the children of.
public static java.util.List getChildElementsAsList(org.w3c.dom.Element element)
element - The Element to get the children of.
public static java.util.List getChildElementsAsList(org.w3c.dom.Element element,
java.lang.String elementTagName)
element - The Element to get the children of.elementTagName - The tag name of the children, including
the namespace prefix, if any.
public static org.w3c.dom.Element getElement(org.w3c.dom.Document document,
java.lang.String elementName)
document - The DOM document to find the Element in.elementName - The Element name to look for, including
the namespace prefix, if any.
public static org.w3c.dom.Element getElement(org.w3c.dom.Document document,
java.lang.String elementName,
int index)
document - The DOM document to find the Element in.elementName - The Element name to look for, including
the namespace prefix, if any.index - The number of the occurence of the XML Element to return.
public static org.w3c.dom.Element getElement(org.w3c.dom.Element parentElement,
java.lang.String elementName)
parentElement - The parent ElementelementName - The Element name to look for, including
the namespace prefix, if any.
public static org.w3c.dom.Element getElement(org.w3c.dom.Element parentElement,
java.lang.String elementName,
int index)
parentElement - The parent ElementelementName - The Element name to look for, including
the namespace prefix, if any.index - The index of the Element to return.
public static org.w3c.dom.Element getElement(org.w3c.dom.Element parentElement,
java.lang.String elementName,
java.lang.String attributeName,
java.lang.String attributeValue)
parentElement - The parent ElementelementName - The Element name to look for, including
the namespace prefix, if any.attributeName - The Attribute name to look for.attributeValue - The Attribute value to look for.
public static boolean isElementEmpty(org.w3c.dom.Element element)
element - The XML Element to test.
public static java.lang.String getNodeValue(org.w3c.dom.Node node)
node - The XML Node to get the value of.
public static void setNodeValue(org.w3c.dom.Node node,
java.lang.String value)
node - element The XML Node to set the value of.value - The String value to set.public static java.lang.String getElementValue(org.w3c.dom.Element element)
element - The XML Element to get the value of.
public static void setElementValue(org.w3c.dom.Element element,
java.lang.String value)
element - The XML Element to set the value of.value - The String value to set.public static org.w3c.dom.Attr[] getElementAttributes(org.w3c.dom.Element element)
element - The XML Element to get the attributes of.
public static java.util.Properties getElementAttributesAsProperties(org.w3c.dom.Element element)
element - The XML Element to get the attributes of.
public static java.lang.String getElementAttributeValue(org.w3c.dom.Element element,
java.lang.String attributeName)
element - The document Element.attributeName - The name of the attribute to get the value of.
public static org.w3c.dom.Element createElement(java.lang.String name)
throws java.lang.Exception
name - The name for the Element.
java.lang.Exception - if an error is encountered while creating the Element.
public static org.w3c.dom.Element createElement(java.lang.String namespaceURI,
java.lang.String name)
throws java.lang.Exception
name - The name for the Element.
java.lang.Exception - if an error is encountered while creating the Element.
public static org.w3c.dom.Attr createAttribute(java.lang.String name,
java.lang.String value)
throws java.lang.Exception
name - The name for the Element.value - An optional value for the Attribute.
java.lang.Exception - if an error is encountered while creating the Element.
public static org.w3c.dom.Attr createAttribute(java.lang.String namespaceURI,
java.lang.String name,
java.lang.String value)
throws java.lang.Exception
namespaceURI - An optional namespaceURI for the Attribute.name - The name for the Element.value - An optional value for the Attribute.
java.lang.Exception - if an error is encountered while creating the Element.public static void main(java.lang.String[] args)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||