Package org.vast.xml
Class XMLDocument
java.lang.Object
org.vast.xml.XMLDocument
Wrapper class for a DOM XML document
- Since:
- Nov 3, 2005
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Document
w3c.Document objectprotected static DOMImplementation
map linking each (local) ID (String) to an Element (w3c.Element)map linking NS Prefix (String) to a NS URI (String)map linking NS URI (String) to a NS prefix (String)protected URI
document URI -
Constructor Summary
ConstructorsConstructorDescriptionXMLDocument
(InputStream inputStream, boolean validate) XMLDocument
(InputStream inputStream, boolean validate, Map<String, String> schemaLocations) XMLDocument
(org.vast.xml.QName qname) XMLDocument
(Document doc) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a pair identifier/node in the listvoid
Adds mapping from uri to prefix and prefix to uri for further lookupsGet the dom document objectGet this dom document root elementgetElementByID
(String id) Retrieve a node from the unique IDgetNSPrefix
(String nsUri) Retrieve a namespace prefix for this documentRetrieves the namespace tableRetrieves the namespace uri matching the given prefixgetUri()
protected Document
parseDOM
(InputStream inputStream, boolean validate, Map<String, String> schemaLocations) Parse DOM from given input streamprotected Document
parseDOM_JAXP
(InputStream inputStream, boolean validate, Map<String, String> schemaLocations) protected Document
parseDOM_LS
(InputStream inputStream, boolean validate, Map<String, String> schemaLocations) void
readIdentifiers
(Element elt, boolean recursive) This function looks and stores all identifiers attributes found in the document
This adds every id it founds to the corresponding hashtable in the given XMLDocument
This is called recursively for each child nodevoid
readNamespaces
(Element elt, boolean recursive) Reads all the namespace prefix:domain pairs and store them in the hashtable of the XMLDocumentvoid
serialize
(Node node, OutputStream out, boolean pretty) Helper method to serialize this DOM to a streamprotected void
serializeDOM_JAXP
(Element elt, OutputStream out, boolean pretty) protected void
serializeDOM_LS
(Element elt, OutputStream out, boolean pretty) void
-
Field Details
-
domImpl
-
uri
document URI -
domDocument
w3c.Document object -
identifiers
map linking each (local) ID (String) to an Element (w3c.Element) -
nsUriToPrefix
map linking NS URI (String) to a NS prefix (String) -
nsPrefixToUri
map linking NS Prefix (String) to a NS URI (String)
-
-
Constructor Details
-
XMLDocument
public XMLDocument() -
XMLDocument
public XMLDocument(org.vast.xml.QName qname) -
XMLDocument
-
XMLDocument
- Throws:
DOMHelperException
-
XMLDocument
public XMLDocument(InputStream inputStream, boolean validate, Map<String, String> schemaLocations) throws DOMHelperException- Throws:
DOMHelperException
-
-
Method Details
-
addId
Adds a pair identifier/node in the list- Parameters:
id
- XML Identifierelt
- XML Node
-
addNS
Adds mapping from uri to prefix and prefix to uri for further lookups- Parameters:
prefix
-uri
-
-
getElementByID
Retrieve a node from the unique ID- Parameters:
id
- Node identifier- Returns:
- the corresponding Node object
- Throws:
DOMHelperException
- if no node with the given ID belongs to the document
-
getNSPrefix
Retrieve a namespace prefix for this document- Parameters:
nsUri
- namespace domain uri- Returns:
- the prefix string or null if not found
-
getNSUri
Retrieves the namespace uri matching the given prefix- Parameters:
nsPrefix
- namespace prefix string- Returns:
- the uri or null if not found
-
getNSTable
Retrieves the namespace table- Returns:
- map of namespace prefix to URI
-
getDocument
Get the dom document object- Returns:
- Document object
-
getDocumentElement
Get this dom document root element- Returns:
- Element
-
getUri
- Returns:
- Returns the base uri of the document.
-
setUri
- Parameters:
uri
- The uri to set as base uri for this document.
-
parseDOM
protected Document parseDOM(InputStream inputStream, boolean validate, Map<String, String> schemaLocations) throws DOMHelperExceptionParse DOM from given input stream- Parameters:
inputStream
- Stream containing XML file we want to parsevalidate
- boolean if true force the validation process with the schema- Returns:
- The XMLDocument object created
- Throws:
DOMHelperException
- if a problem occur during parsing
-
parseDOM_LS
protected Document parseDOM_LS(InputStream inputStream, boolean validate, Map<String, String> schemaLocations) throws DOMHelperException, IOException- Throws:
DOMHelperException
IOException
-
parseDOM_JAXP
protected Document parseDOM_JAXP(InputStream inputStream, boolean validate, Map<String, String> schemaLocations) throws ParserConfigurationException, IOException, SAXException -
serialize
Helper method to serialize this DOM to a stream- Parameters:
node
-out
-pretty
- set to true to indent output- Throws:
IOException
-
serializeDOM_LS
- Throws:
LSException
-
serializeDOM_JAXP
protected void serializeDOM_JAXP(Element elt, OutputStream out, boolean pretty) throws TransformerException - Throws:
TransformerException
-
readIdentifiers
This function looks and stores all identifiers attributes found in the document
This adds every id it founds to the corresponding hashtable in the given XMLDocument
This is called recursively for each child node- Parameters:
elt
- the DOM element where to start the searchrecursive
- if true, all children elements are also processed recursively
-
readNamespaces
Reads all the namespace prefix:domain pairs and store them in the hashtable of the XMLDocument- Parameters:
elt
- the DOM element where to start the searchrecursive
- if true, all children elements are also processed recursively
-