|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--at.gv.egovernment.moa.util.DOMUtils
Various utility functions for handling XML DOM trees. The parsing methods in this class make use of some features internal to the Xerces DOM parser, mainly for performance reasons. As soon as JAXP (currently at version 1.2) is better at schema handling, it should be used as the parser interface.
| Constructor Summary | |
DOMUtils()
|
|
| Method Summary | |
static void |
addSchemaToPool(InputStream inputStream,
String systemId)
Preparse a schema and add it to the schema pool. |
static boolean |
checkAttributeParentsInNodeList(org.w3c.dom.NodeList nodes)
Check, that each attribute node in the given NodeList has its
parent in the NodeList as well. |
static Set |
collectNamespaceURIs(org.w3c.dom.Element context)
Collect all the namespace URIs used in the subtree of a given element. |
static Map |
getNamespaceDeclarations(org.w3c.dom.Node node)
Build the namespace prefix to namespace URL mapping in effect for a given node. |
static String |
getText(org.w3c.dom.Node node)
Return the text that a node contains. |
static boolean |
isAncestor(org.w3c.dom.Element candAnc,
org.w3c.dom.Node cand)
Check, if a given DOM element is an ancestor of a given node. |
static void |
localizeNamespaceDeclarations(org.w3c.dom.Element context)
Add all namespace declarations declared in the parent(s) of a given element and used in the subtree of the given element to the given element. |
static org.w3c.dom.DocumentFragment |
nodeList2DocumentFragment(org.w3c.dom.NodeList nodeList)
Convert an unstructured NodeList into a
DocumentFragment. |
static org.w3c.dom.Document |
parseDocument(InputStream inputStream,
boolean validating,
String externalSchemaLocations,
String externalNoNamespaceSchemaLocation)
Parse an XML document from an InputStream.
|
static org.w3c.dom.Document |
parseDocument(InputStream inputStream,
boolean validating,
String externalSchemaLocations,
String externalNoNamespaceSchemaLocation,
org.xml.sax.EntityResolver entityResolver,
org.xml.sax.ErrorHandler errorHandler)
Parse an XML document from an InputStream. |
static org.w3c.dom.Document |
parseDocument(String xmlString,
boolean validating,
String externalSchemaLocations,
String externalNoNamespaceSchemaLocation)
Parse an UTF-8 encoded XML document from a String. |
static org.w3c.dom.Document |
parseDocument(String xmlString,
String encoding,
boolean validating,
String externalSchemaLocations,
String externalNoNamespaceSchemaLocation)
Parse an XML document from a String.
|
static org.w3c.dom.Element |
parseXmlValidating(InputStream inputStream)
A convenience method to parse an XML document validating. |
static String |
serializeNode(org.w3c.dom.Node node)
Serialize the given DOM node. |
static byte[] |
serializeNode(org.w3c.dom.Node node,
String xmlEncoding)
Serialize the given DOM node to a byte array. |
static boolean |
validateElement(org.w3c.dom.Element element,
String externalSchemaLocations,
String externalNoNamespaceSchemaLocation)
Schema validate a given DOM element. |
| 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 void addSchemaToPool(InputStream inputStream,
String systemId)
throws IOException
inputStream - An InputStream providing the contents of
the schema.systemId - The systemId to use for the schema.IOException - An error occurred reading the schema.
public static org.w3c.dom.Document parseDocument(InputStream inputStream,
boolean validating,
String externalSchemaLocations,
String externalNoNamespaceSchemaLocation,
org.xml.sax.EntityResolver entityResolver,
org.xml.sax.ErrorHandler errorHandler)
throws org.xml.sax.SAXException,
IOException,
javax.xml.parsers.ParserConfigurationException
InputStream.inputStream - The InputStream containing the XML
document.validating - If true, parse validating.externalSchemaLocations - A String containing namespace
URI to schema location pairs, the same way it is accepted by the xsi:
schemaLocation attribute.externalNoNamespaceSchemaLocation - The schema location of the
schema for elements without a namespace, the same way it is accepted by the
xsi:noNamespaceSchemaLocation attribute.entityResolver - An EntityResolver to resolve external
entities (schemas and DTDs). If null, it will not be set.errorHandler - An ErrorHandler to decide what to do
with parsing errors. If null, it will not be set.org.xml.sax.SAXException - An error occurred parsing the document.IOException - An error occurred reading the document.javax.xml.parsers.ParserConfigurationException - An error occurred configuring the XML
parser.
public static org.w3c.dom.Document parseDocument(InputStream inputStream,
boolean validating,
String externalSchemaLocations,
String externalNoNamespaceSchemaLocation)
throws org.xml.sax.SAXException,
IOException,
javax.xml.parsers.ParserConfigurationException
InputStream.
It uses a MOAEntityResolver as the EntityResolver
and a MOAErrorHandler as the ErrorHandler.inputStream - The InputStream containing the XML
document.validating - If true, parse validating.externalSchemaLocations - A String containing namespace
URI to schema location pairs, the same way it is accepted by the xsi:
schemaLocation attribute.externalNoNamespaceSchemaLocation - The schema location of the
schema for elements without a namespace, the same way it is accepted by the
xsi:noNamespaceSchemaLocation attribute.org.xml.sax.SAXException - An error occurred parsing the document.IOException - An error occurred reading the document.javax.xml.parsers.ParserConfigurationException - An error occurred configuring the XML
parser.
public static org.w3c.dom.Document parseDocument(String xmlString,
String encoding,
boolean validating,
String externalSchemaLocations,
String externalNoNamespaceSchemaLocation)
throws org.xml.sax.SAXException,
IOException,
javax.xml.parsers.ParserConfigurationException
String.
It uses a MOAEntityResolver as the EntityResolver
and a MOAErrorHandler as the ErrorHandler.xmlString - The String containing the XML document.encoding - The encoding of the XML document.validating - If true, parse validating.externalSchemaLocations - A String containing namespace
URI to schema location pairs, the same way it is accepted by the xsi:
schemaLocation attribute.externalNoNamespaceSchemaLocation - The schema location of the
schema for elements without a namespace, the same way it is accepted by the
xsi:noNamespaceSchemaLocation attribute.org.xml.sax.SAXException - An error occurred parsing the document.IOException - An error occurred reading the document.javax.xml.parsers.ParserConfigurationException - An error occurred configuring the XML
parser.
public static org.w3c.dom.Document parseDocument(String xmlString,
boolean validating,
String externalSchemaLocations,
String externalNoNamespaceSchemaLocation)
throws org.xml.sax.SAXException,
IOException,
javax.xml.parsers.ParserConfigurationException
String.xmlString - The String containing the XML document.validating - If true, parse validating.externalSchemaLocations - A String containing namespace
URI to schema location pairs, the same way it is accepted by the xsi:
schemaLocation attribute.externalNoNamespaceSchemaLocation - The schema location of the
schema for elements without a namespace, the same way it is accepted by the
xsi:noNamespaceSchemaLocation attribute.org.xml.sax.SAXException - An error occurred parsing the document.IOException - An error occurred reading the document.javax.xml.parsers.ParserConfigurationException - An error occurred configuring the XML
parser.
public static org.w3c.dom.Element parseXmlValidating(InputStream inputStream)
throws javax.xml.parsers.ParserConfigurationException,
org.xml.sax.SAXException,
IOException
inputStream - The InputStream containing the XML
document.org.xml.sax.SAXException - An error occurred parsing the document.IOException - An error occurred reading the document.javax.xml.parsers.ParserConfigurationException - An error occurred configuring the XML
parser.
public static boolean validateElement(org.w3c.dom.Element element,
String externalSchemaLocations,
String externalNoNamespaceSchemaLocation)
throws javax.xml.parsers.ParserConfigurationException,
IOException,
org.xml.sax.SAXException,
javax.xml.transform.TransformerException
element - The element to validate.externalSchemaLocations - A String containing namespace
URI to schema location pairs, the same way it is accepted by the xsi:
schemaLocation attribute.externalNoNamespaceSchemaLocation - The schema location of the
schema for elements without a namespace, the same way it is accepted by the
xsi:noNamespaceSchemaLocation attribute.true, if the element validates against
the schemas declared in it.org.xml.sax.SAXException - An error occurred parsing the document.IOException - An error occurred reading the document from its
serialized representation.javax.xml.parsers.ParserConfigurationException - An error occurred configuring the XMLjavax.xml.transform.TransformerException - An error occurred serializing the element.
public static String serializeNode(org.w3c.dom.Node node)
throws javax.xml.transform.TransformerException,
IOException
node - The node to serialize.String representation of the given DOM
node.javax.xml.transform.TransformerException - An error occurred transforming the
node to a String.IOException - An IO error occurred writing the node to a byte array.
public static byte[] serializeNode(org.w3c.dom.Node node,
String xmlEncoding)
throws javax.xml.transform.TransformerException,
IOException
node - The node to serialize.xmlEncoding - The XML encoding to use.String.javax.xml.transform.TransformerException - An error occurred transforming the node to a
byte array.IOException - An IO error occurred writing the node to a byte array.public static String getText(org.w3c.dom.Node node)
node - A DOM node from which to extract text.public static Map getNamespaceDeclarations(org.w3c.dom.Node node)
node - The context node for which build the map.String value to String value mapping).public static void localizeNamespaceDeclarations(org.w3c.dom.Element context)
context - The element to which to add the namespaces.public static Set collectNamespaceURIs(org.w3c.dom.Element context)
context - The element that should be searched for namespace URIs.context,
including the ones used in context itself.public static boolean checkAttributeParentsInNodeList(org.w3c.dom.NodeList nodes)
NodeList has its
parent in the NodeList as well.nodes - The NodeList to check.true, if each attribute node in nodes
has its parent in nodes as well.
public static org.w3c.dom.DocumentFragment nodeList2DocumentFragment(org.w3c.dom.NodeList nodeList)
throws javax.xml.parsers.ParserConfigurationException
NodeList into a
DocumentFragment.nodeList - Contains the node list to be converted into a DOM
DocumentFragment.javax.xml.parsers.ParserConfigurationException - An error occurred creating the
DocumentFragment.
public static boolean isAncestor(org.w3c.dom.Element candAnc,
org.w3c.dom.Node cand)
candAnc - The DOM element to check for being the ancestor.cand - The node to check for being the child.true, if candAnc is an (indirect)
ancestor of cand; false otherwise.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||