electric.xml
Class Document

java.lang.Object
  extended byelectric.xml.Node
      extended byelectric.xml.Child
          extended byelectric.xml.Parent
              extended byelectric.xml.Document
All Implemented Interfaces:
java.lang.Cloneable, org.w3c.dom.Document, IDOMConstants, IXMLConstants, org.w3c.dom.Node, java.io.Serializable

public class Document
extends Parent
implements org.w3c.dom.Document

Document represents an XML document, and includes methods for parsing XML and accessing a document's root. When parsing XML, you can supply an optional Hashtable of namespace values that acts as global context.

Author:
webMethods
See Also:
Serialized Form

Field Summary
static int KEEP_WHITESPACE
          Keep whitespace during parsing.
static int MAJOR_VERSION
          The major version.
static int MINOR_VERSION
          The minor version.
 
Fields inherited from class electric.xml.Parent
children
 
Fields inherited from class electric.xml.Child
parent
 
Fields inherited from class electric.xml.Node
list, next, prev
 
Fields inherited from interface org.w3c.dom.Node
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE
 
Fields inherited from interface electric.xml.IXMLConstants
ATTLIST_START, ATTLIST_STOP, CDATA, CDATA_START, CDATA_STOP, CLOSE_TAG, COLON, COMMENT_START, COMMENT_STOP, DOCTYPE_START, DOCTYPE_STOP, ELEMENTDECL_START, ELEMENTDECL_STOP, ENCODING, ENTITYDECL_START, ENTITYDECL_STOP, ID, ID_CASE, INSTRUCTION_START, INSTRUCTION_STOP, NEGATIVE_INFINITY, NOT_A_NUMBER, NOTATIONDECL_START, NOTATIONDECL_STOP, NULL, OPEN_TAG, POSITIVE_INFINITY, PUBLIC, SPECIALS, STANDALONE, SUBSTITUTES, SYSTEM, UNDEFINED, VERSION, XML, XML_NAMESPACE, XMLDECL_START, XMLDECL_STOP, XMLNS, XMLNS_NAMESPACE
 
Fields inherited from interface electric.xml.IDOMConstants
CDATA_SECTION_NAME, COMMENT_NAME, CORE, DOCUMENT_FRAGMENT_NAME, DOCUMENT_NAME, HIERARCHY_REQUEST_ERR, TEXT_NAME
 
Constructor Summary
Document()
          Construct an empty Document.
Document(byte[] bytes)
          Construct a Document built by parsing the specified bytes.
Document(byte[] bytes, java.util.Hashtable context)
          Construct a Document built by parsing the specified bytes.
Document(byte[] bytes, java.util.Hashtable context, int flags)
          Construct a Document built by parsing the specified bytes.
Document(byte[] bytes, int flags)
          Construct a Document built by parsing the specified bytes.
Document(Document document)
          Construct a copy of the specified document.
Document(Element root)
          Construct a Document with the specified root element.
Document(java.io.File file)
          Construct a Document built by parsing the File.
Document(java.io.File file, int flags)
          Construct a Document built by parsing the File.
Document(java.util.Hashtable context)
          Construct an empty Document.
Document(java.io.InputStream stream)
          Construct a Document built by parsing the InputStream.
Document(java.io.InputStream stream, int flags)
          Construct a Document built by parsing the InputStream.
Document(NodeReader nodeReader)
           
Document(NodeReader nodeReader, java.util.Hashtable context)
           
Document(java.io.Reader reader)
          Construct a Document built by parsing the contents of the Reader.
Document(java.io.Reader reader, java.util.Hashtable context)
          Construct a Document built by parsing the contents of the Reader.
Document(java.io.Reader reader, java.util.Hashtable context, int flags)
           
Document(java.io.Reader reader, int flags)
          Construct a Document built by parsing the contents of the Reader.
Document(java.lang.String string)
          Construct a Document built by parsing the specified string.
Document(java.lang.String string, int flags)
          Construct a Document built by parsing the specified string.
 
Method Summary
protected  void addNamespacePrefixes(java.lang.String namespace, java.util.Vector prefixes, java.util.Vector matches)
          Add all the prefixes that map to a particular namespace value in my context to the specified vector.
 void addPotentialNamespacePrefix(java.lang.String prefix, java.lang.String namespace)
          Set up a namespace to appear in the document if it is ever asked for.
 org.w3c.dom.Node appendChild(org.w3c.dom.Node newChild)
          Adds the node newChild to the end of the list of children of this node.
 java.lang.Object clone()
          Return a clone of this Document.
 org.w3c.dom.Attr createAttribute(java.lang.String name)
           
 org.w3c.dom.Attr createAttributeNS(java.lang.String namespaceURI, java.lang.String qualifiedName)
           
 org.w3c.dom.CDATASection createCDATASection(java.lang.String data)
           
 org.w3c.dom.Comment createComment(java.lang.String data)
           
 org.w3c.dom.DocumentFragment createDocumentFragment()
           
 org.w3c.dom.Element createElement(java.lang.String tagName)
           
 org.w3c.dom.Element createElementNS(java.lang.String namespaceURI, java.lang.String qualifiedName)
           
 org.w3c.dom.EntityReference createEntityReference(java.lang.String name)
           
 org.w3c.dom.ProcessingInstruction createProcessingInstruction(java.lang.String target, java.lang.String data)
           
 org.w3c.dom.Text createTextNode(java.lang.String data)
           
 java.util.Hashtable getContext()
          Return my context.
 org.w3c.dom.DocumentType getDoctype()
           
 DocType getDocType()
          Return the DocType, or null if there is none.
 Document getDocument()
          Return myself.
 org.w3c.dom.Element getDocumentElement()
           
 org.w3c.dom.Element getElementById(java.lang.String elementId)
           
 org.w3c.dom.NodeList getElementsByTagName(java.lang.String tagName)
           
 org.w3c.dom.NodeList getElementsByTagNameNS(java.lang.String namespaceURI, java.lang.String localName)
           
 java.lang.String getEncoding()
          Return the encoding for this document, which is UTF-8 by default.
 org.w3c.dom.DOMImplementation getImplementation()
           
 java.lang.String getNamespace(java.lang.String prefix)
          Return the value of the namespace with the specified prefix, or null if there is none.
 java.lang.String getNamespacePrefix(java.lang.String namespace)
          Return a prefix that maps to a particular namespace value, searching from the current element up through its parents.
 java.lang.String getNodeName()
          Return "#document".
 short getNodeType()
          Return DOCUMENT_NODE.
 Element getRoot()
          Return the top-level element in this Document.
 boolean getStandalone()
          Return true if this document is standalone, which is false by default.
 java.lang.String getVersion()
          Return the version of this document, which is 1.0 by default.
 boolean getWriteXMLDecl()
          Return true if my XML declaration will be written.
 org.w3c.dom.Node importNode(org.w3c.dom.Node importedNode, boolean deep)
           
 boolean isStripped()
          Return true if whitespace was stripped during parsing.
 Element newRoot()
          Set the root to an empty element with no name.
 void read(NodeReader reader)
           
 void setContext(java.util.Hashtable context)
          Set my context.
 void setEncoding(java.lang.String encoding)
          Set the encoding for this document.
 Element setRoot(Element element)
          Set the root to the specified element.
 Element setRoot(java.lang.String name)
          Set the root to an empty element with the specified name.
 Element setRoot(java.lang.String prefix, java.lang.String name)
          Set the root to an empty element with the specified namespace prefix and name.
 Element setRoot(java.lang.String prefix, java.lang.String name, java.lang.String namespace)
          Set the root to an empty element with the specified namespace prefix and name.
 void setStandalone(boolean standalone)
          Set the standalone value for this document.
 void setVersion(java.lang.String version)
          Set the version for this document.
 void setWriteXMLDecl(boolean flag)
          If flag is true, write my XML declaration when printing.
 int size()
           
 void write(NodeWriter writer)
          Write myself to the specified writer, starting at the specified indent level.
 
Methods inherited from class electric.xml.Parent
addChild, addComment, addElement, addElement, addElement, addElement, getChildNodes, getChildren, getElement, getElement, getElement, getElementAt, getElements, getElements, getElements, getElements, getElementWithId, getFirstChild, getFirstElement, getLastChild, hasChildNodes, hasChildren, hasElement, hasElements, insertBefore, insertChild, insertComment, insertElement, insertElement, insertElement, insertElement, needElement, needElement, removeChild, removeChildren, removeElement, removeElement, removeElement, removeElementAt, removeElements, removeElements, removeElements, removeElements, replaceChild, setElement, setElement, setElementAt
 
Methods inherited from class electric.xml.Child
cloneNode, getByteArray, getByteArray, getByteArray, getBytes, getBytes, getBytes, getNextSiblingChild, getOwnerDocument, getParent, getParentNode, getPreviousSiblingChild, replaceWith, setNextSiblingChild, setParent, setPreviousSiblingChild, toString, toString, write, write, write
 
Methods inherited from class electric.xml.Node
getAttributes, getLocalName, getNamespaceURI, getNextSibling, getNextSiblingNode, getNode, getNode, getNodes, getNodeValue, getPrefix, getPreviousSibling, getPreviousSiblingNode, hasAttributes, isSupported, normalize, remove, setNextSiblingNode, setNodeValue, setPrefix, setPreviousSiblingNode
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.w3c.dom.Node
cloneNode, getAttributes, getChildNodes, getFirstChild, getLastChild, getLocalName, getNamespaceURI, getNextSibling, getNodeValue, getOwnerDocument, getParentNode, getPrefix, getPreviousSibling, hasAttributes, hasChildNodes, insertBefore, isSupported, normalize, removeChild, replaceChild, setNodeValue, setPrefix
 

Field Detail

KEEP_WHITESPACE

public static final int KEEP_WHITESPACE
Keep whitespace during parsing.

See Also:
Constant Field Values

MAJOR_VERSION

public static final int MAJOR_VERSION
The major version.

See Also:
Constant Field Values

MINOR_VERSION

public static final int MINOR_VERSION
The minor version.

See Also:
Constant Field Values
Constructor Detail

Document

public Document()
Construct an empty Document.


Document

public Document(java.util.Hashtable context)
Construct an empty Document.

Parameters:
context - A Hashtable of global namespaces.

Document

public Document(java.lang.String string)
         throws ParseException
Construct a Document built by parsing the specified string.

Parameters:
string - An XML document.
Throws:
ParseException - If an error occurs during parsing.

Document

public Document(java.lang.String string,
                int flags)
         throws ParseException
Construct a Document built by parsing the specified string.

Parameters:
string - An XML document.
flags - Parse flags.
Throws:
ParseException - If an error occurs during parsing.

Document

public Document(byte[] bytes)
         throws ParseException
Construct a Document built by parsing the specified bytes.

Parameters:
bytes - A byte array that is converted into a String.
Throws:
ParseException - If an error occurs during parsing.

Document

public Document(byte[] bytes,
                int flags)
         throws ParseException
Construct a Document built by parsing the specified bytes.

Parameters:
bytes - A byte array that is converted into a String.
flags - Parse flags.
Throws:
ParseException - If an error occurs during parsing.

Document

public Document(byte[] bytes,
                java.util.Hashtable context)
         throws ParseException
Construct a Document built by parsing the specified bytes.

Parameters:
bytes - A byte array that is converted into a String.
context - A Hashtable of global namespaces.
Throws:
ParseException - If an error occurs during parsing.

Document

public Document(byte[] bytes,
                java.util.Hashtable context,
                int flags)
         throws ParseException
Construct a Document built by parsing the specified bytes.

Parameters:
bytes - A byte array that is converted into a String.
context - A Hashtable of global namespaces.
flags - Parse flags.
Throws:
ParseException - If an error occurs during parsing.

Document

public Document(java.io.File file)
         throws ParseException
Construct a Document built by parsing the File.

Parameters:
file - The File to parse.
Throws:
ParseException - If an error occurs during parsing.

Document

public Document(java.io.File file,
                int flags)
         throws ParseException
Construct a Document built by parsing the File.

Parameters:
file - The File to parse.
flags - Parse flags.
Throws:
ParseException - If an error occurs during parsing.

Document

public Document(java.io.InputStream stream)
         throws ParseException
Construct a Document built by parsing the InputStream.

Parameters:
stream - The InputStream to parse.
Throws:
ParseException - If an error occurs during parsing.

Document

public Document(java.io.InputStream stream,
                int flags)
         throws ParseException
Construct a Document built by parsing the InputStream.

Parameters:
stream - The InputStream to parse.
flags - Parse flags.
Throws:
ParseException - If an error occurs during parsing.

Document

public Document(java.io.Reader reader)
         throws ParseException
Construct a Document built by parsing the contents of the Reader.

Parameters:
reader - The Reader.
Throws:
ParseException - If an error occurs during parsing.

Document

public Document(java.io.Reader reader,
                int flags)
         throws ParseException
Construct a Document built by parsing the contents of the Reader.

Parameters:
reader - The Reader.
flags - Parse flags.
Throws:
ParseException - If an error occurs during parsing.

Document

public Document(java.io.Reader reader,
                java.util.Hashtable context)
         throws ParseException
Construct a Document built by parsing the contents of the Reader.

Parameters:
reader - The Reader.
context - A Hashtable of global namespaces.
Throws:
ParseException - If an error occurs during parsing.

Document

public Document(java.io.Reader reader,
                java.util.Hashtable context,
                int flags)
         throws ParseException
Parameters:
reader -
context -
flags -
Throws:
ParseException

Document

public Document(NodeReader nodeReader)
         throws ParseException
Parameters:
nodeReader -
Throws:
ParseException

Document

public Document(NodeReader nodeReader,
                java.util.Hashtable context)
         throws ParseException
Parameters:
nodeReader -
context -
Throws:
ParseException

Document

public Document(Element root)
Construct a Document with the specified root element.

Parameters:
root - The root Element.

Document

public Document(Document document)
Construct a copy of the specified document.

Parameters:
document - The Document to copy.
Method Detail

isStripped

public boolean isStripped()
Return true if whitespace was stripped during parsing.


clone

public java.lang.Object clone()
Return a clone of this Document.

Specified by:
clone in class Child

getDocument

public Document getDocument()
Return myself.

Overrides:
getDocument in class Child

getRoot

public Element getRoot()
Return the top-level element in this Document.

Overrides:
getRoot in class Child

newRoot

public Element newRoot()
Set the root to an empty element with no name.

Returns:
The new root.

setRoot

public Element setRoot(Element element)
Set the root to the specified element.

Parameters:
element - The new root.
Returns:
The new root.

setRoot

public Element setRoot(java.lang.String name)
Set the root to an empty element with the specified name.

Parameters:
name - The name of the new root.
Returns:
The new root.

setRoot

public Element setRoot(java.lang.String prefix,
                       java.lang.String name)
Set the root to an empty element with the specified namespace prefix and name.

Parameters:
prefix - The namespace prefix of the new root.
name - The name of the new root.
Returns:
The new root.

setRoot

public Element setRoot(java.lang.String prefix,
                       java.lang.String name,
                       java.lang.String namespace)
Set the root to an empty element with the specified namespace prefix and name.

Parameters:
prefix - The namespace prefix of the new root.
name - The name of the new root.
namespace - The namepace the prefix should be associated with
Returns:
The new root.

getDocType

public DocType getDocType()
Return the DocType, or null if there is none.


read

public void read(NodeReader reader)
          throws java.io.IOException,
                 NamespaceException
Overrides:
read in class Node
Parameters:
reader -
Throws:
java.io.IOException
NamespaceException

write

public void write(NodeWriter writer)
           throws java.io.IOException
Write myself to the specified writer, starting at the specified indent level. If the indent level is -1, no indentation will occur, otherwise the indent level increases by two at each child node.

Overrides:
write in class Node
Parameters:
writer - The nodeWriter.
Throws:
java.io.IOException - If an I/O exception occurs.

getVersion

public java.lang.String getVersion()
Return the version of this document, which is 1.0 by default.


setVersion

public void setVersion(java.lang.String version)
Set the version for this document.

Parameters:
version - The new version.

getEncoding

public java.lang.String getEncoding()
Return the encoding for this document, which is UTF-8 by default.


setEncoding

public void setEncoding(java.lang.String encoding)
Set the encoding for this document.

Parameters:
encoding - The new encoding.

getStandalone

public boolean getStandalone()
Return true if this document is standalone, which is false by default.


setStandalone

public void setStandalone(boolean standalone)
Set the standalone value for this document.

Parameters:
standalone - The new standalone value.

setWriteXMLDecl

public void setWriteXMLDecl(boolean flag)
If flag is true, write my XML declaration when printing. By default, this flag is equal to true.

Parameters:
flag - The new setting.

getWriteXMLDecl

public boolean getWriteXMLDecl()
Return true if my XML declaration will be written.


getContext

public java.util.Hashtable getContext()
Return my context.


setContext

public void setContext(java.util.Hashtable context)
Set my context.

Parameters:
context - A Hashtable of global namespaces.

getNamespace

public java.lang.String getNamespace(java.lang.String prefix)
Return the value of the namespace with the specified prefix, or null if there is none.

Overrides:
getNamespace in class Parent
Parameters:
prefix - The prefix.

addNamespacePrefixes

protected void addNamespacePrefixes(java.lang.String namespace,
                                    java.util.Vector prefixes,
                                    java.util.Vector matches)
Add all the prefixes that map to a particular namespace value in my context to the specified vector.

Overrides:
addNamespacePrefixes in class Parent
Parameters:
namespace - The namespace to match
prefixes - All the prefixes so far.
matches - All the prefixes that matched.

getNamespacePrefix

public java.lang.String getNamespacePrefix(java.lang.String namespace)
Return a prefix that maps to a particular namespace value, searching from the current element up through its parents. Return null if none is found.

Overrides:
getNamespacePrefix in class Parent
Parameters:
namespace - The namespace to match.

addPotentialNamespacePrefix

public void addPotentialNamespacePrefix(java.lang.String prefix,
                                        java.lang.String namespace)
Set up a namespace to appear in the document if it is ever asked for. This allows for xsd to be defined if it is referenced, but not be used if it isn't referenced.

Parameters:
prefix -
namespace -

size

public int size()
Overrides:
size in class Parent

appendChild

public org.w3c.dom.Node appendChild(org.w3c.dom.Node newChild)
                             throws org.w3c.dom.DOMException
Adds the node newChild to the end of the list of children of this node.

Specified by:
appendChild in interface org.w3c.dom.Node
Overrides:
appendChild in class Parent
Parameters:
newChild - The node to add. If the newChild is a ProcessingInstruction, check to see if it's the XML decl, and deal with it appropriately to avoid duplicate decls.
Throws:
org.w3c.dom.DOMException

getNodeType

public short getNodeType()
Return DOCUMENT_NODE.

Specified by:
getNodeType in interface org.w3c.dom.Node
Overrides:
getNodeType in class Node

getNodeName

public java.lang.String getNodeName()
Return "#document".

Specified by:
getNodeName in interface org.w3c.dom.Node
Overrides:
getNodeName in class Node

createAttribute

public org.w3c.dom.Attr createAttribute(java.lang.String name)
Specified by:
createAttribute in interface org.w3c.dom.Document
Parameters:
name - The name.

createAttributeNS

public org.w3c.dom.Attr createAttributeNS(java.lang.String namespaceURI,
                                          java.lang.String qualifiedName)
Specified by:
createAttributeNS in interface org.w3c.dom.Document
Parameters:
namespaceURI -
qualifiedName -

createCDATASection

public org.w3c.dom.CDATASection createCDATASection(java.lang.String data)
Specified by:
createCDATASection in interface org.w3c.dom.Document
Parameters:
data -

createComment

public org.w3c.dom.Comment createComment(java.lang.String data)
Specified by:
createComment in interface org.w3c.dom.Document
Parameters:
data -

createDocumentFragment

public org.w3c.dom.DocumentFragment createDocumentFragment()
Specified by:
createDocumentFragment in interface org.w3c.dom.Document

createElement

public org.w3c.dom.Element createElement(java.lang.String tagName)
Specified by:
createElement in interface org.w3c.dom.Document
Parameters:
tagName -

createElementNS

public org.w3c.dom.Element createElementNS(java.lang.String namespaceURI,
                                           java.lang.String qualifiedName)
Specified by:
createElementNS in interface org.w3c.dom.Document
Parameters:
namespaceURI -
qualifiedName -

createEntityReference

public org.w3c.dom.EntityReference createEntityReference(java.lang.String name)
Specified by:
createEntityReference in interface org.w3c.dom.Document
Parameters:
name -

createProcessingInstruction

public org.w3c.dom.ProcessingInstruction createProcessingInstruction(java.lang.String target,
                                                                     java.lang.String data)
Specified by:
createProcessingInstruction in interface org.w3c.dom.Document
Parameters:
target -
data -

createTextNode

public org.w3c.dom.Text createTextNode(java.lang.String data)
Specified by:
createTextNode in interface org.w3c.dom.Document
Parameters:
data -

getDoctype

public org.w3c.dom.DocumentType getDoctype()
Specified by:
getDoctype in interface org.w3c.dom.Document

getDocumentElement

public org.w3c.dom.Element getDocumentElement()
Specified by:
getDocumentElement in interface org.w3c.dom.Document

getElementById

public org.w3c.dom.Element getElementById(java.lang.String elementId)
Specified by:
getElementById in interface org.w3c.dom.Document
Parameters:
elementId -

getElementsByTagName

public org.w3c.dom.NodeList getElementsByTagName(java.lang.String tagName)
Specified by:
getElementsByTagName in interface org.w3c.dom.Document
Parameters:
tagName -

getElementsByTagNameNS

public org.w3c.dom.NodeList getElementsByTagNameNS(java.lang.String namespaceURI,
                                                   java.lang.String localName)
Specified by:
getElementsByTagNameNS in interface org.w3c.dom.Document
Parameters:
namespaceURI -
localName -

getImplementation

public org.w3c.dom.DOMImplementation getImplementation()
Specified by:
getImplementation in interface org.w3c.dom.Document

importNode

public org.w3c.dom.Node importNode(org.w3c.dom.Node importedNode,
                                   boolean deep)
Specified by:
importNode in interface org.w3c.dom.Document
Parameters:
importedNode -
deep -


copyright© 2001-2004 by webMethods All Rights Reserved.