Class com.ibm.xml.parser.TXDocument
java.lang.Object
|
+----com.ibm.xml.parser.Child
|
+----com.ibm.xml.parser.Parent
|
+----com.ibm.xml.parser.TXDocument
- Subclasses:
- TreeFactory.TreeDocument
- public class TXDocument
- extends Parent
- implements Document
The TXDocument class implements the Document interface as defined by the Document Object Model (DOM).
The Document object represents the entire XML document. Conceptually, it is the root
of the document tree, and provides the primary access to the document's data.
It should be noted that factory methods (create*()
) are not used by the parser.
- Version:
- Revision: 35 1.6 src/com/ibm/xml/parser/TXDocument.java, xml4jsrc, xml4j-jtcsv, xml4j_1_0_4
- See Also:
- Document, Parent, Child
Method Summary
|
void
|
acceptPost(Visitor visitor)
Implements the accept operation of the visitor design pattern when the end of
a TXDocument Node is recognized when traversing the document object tree.
|
void
|
acceptPre(Visitor visitor)
Implements the accept operation of the visitor design pattern when the start of
a TXDocument Node is recognized when traversing the document object tree.
|
void
|
addNamespace(NamespacePI namespacePI)
Records the presence of a NamespacePI instance for this Document.
|
java.lang.Object
|
clone()
Clone this Document Node and its children using the appropriate factories.
|
Attribute
|
createAttribute(java.lang.String name,
Node value)
Create and return a new Attribute.
|
AttributeList
|
createAttributeList()
Create and return a new AttributeList.
|
Comment
|
createComment(java.lang.String data)
Create and return a new Comment Node.
|
DocumentContext
|
createDocumentContext()
Create and return a new DocumentContext.
|
Element
|
createElement(java.lang.String tagName,
AttributeList attributes)
Create and return a new Element Node.
|
PI
|
createPI(java.lang.String name,
java.lang.String data)
Create and return a new PI Node.
|
Text
|
createTextNode(java.lang.String data)
Create and return a new Text Node.
|
TreeIterator
|
createTreeIterator(Node node)
Deprecated |
DocumentContext
|
getContextInfo()
Returns this Document's document context.
|
Element
|
getDocumentElement()
Returns this Document's root Element.
|
Node
|
getDocumentType()
Returns this Document's Type Definition (DTD) as a Node.
|
DTD
|
getDTD()
Returns this Document's Type Definition (DTD) as a DTD.
|
NodeIterator
|
getElementsByTagName(java.lang.String qName)
Returns a NodeIterator of matches through all child Element Nodes.
|
java.lang.String
|
getEncoding()
Returns the value of the XML encoding parameter from the XML prolog declaration (e.g.
|
Document
|
getMasterDoc()
Returns the Document Node asociated with this document fragment.
|
NamespacePI
|
getNamespaceFor(java.lang.String nsPrefixName)
Returns the NamespacePI instance which matches the specified namespace prefix name.
|
java.util.Enumeration
|
getNamespaces()
Returns an enumeration of NamespacePI instances defined for this Document.
|
int
|
getNodeType()
Returns that this object is a Document Node.
|
java.lang.String
|
getRootName()
Returns the name of this Document's root Element (not DTD).
|
java.lang.String
|
getStandalone()
Returns if this Document is standalone.
|
java.lang.String
|
getText()
Return all text associated with this Node and its children without considering entities.
|
java.lang.String
|
getVersion()
Returns the XML version of this Document from the XML prolog declaration (e.g.
|
void
|
insert(Child child,
int index)
Insert a Child Node into the specified position.
|
boolean
|
isApplySyntax()
Returns whether a syntax is being applied to this doument.
|
boolean
|
isStandalone()
Returns if this Document is standalone.
|
void
|
printWithFormat(java.io.Writer pw)
Format and print this Node and any children in XML format using the default character
encoding.
|
void
|
printWithFormat(java.io.Writer pw,
java.lang.String encoding)
Format and print this Node and any children in XML format using the specified character
encoding.
|
void
|
printWithFormat(java.io.Writer pw,
java.lang.String encoding,
int indent)
Format and print this Node and any children in XML format, using the specified
character encoding, and indented by indent spaces.
|
void
|
setContextInfo(DocumentContext documentContext)
Sets this Document's document context.
|
void
|
setDocumentElement(Element rootElement)
Sets this Document's root Element.
|
void
|
setDocumentType(Node documentType)
Sets this Document's Type Definition (DTD).
|
void
|
setEncoding(java.lang.String xmlEncoding)
Sets the value of the XML encoding parameter from the XML prolog declaration (e.g.
|
void
|
setMasterDoc(Document document)
Sets the Document Node asociated with this document fragment.
|
java.lang.String
|
setNamespaceParameters(Namespace namespace)
Returns the specified namespace with all aspects of its namespace set
according to NamespacePIs defined in this document, and the raw tag name.
|
void
|
setPrintInternalDTD(boolean printInternalDTD)
Sets whether the internal DTD is printed by the print() methods.
|
void
|
setStandalone(java.lang.String standalone)
Sets if this Document is standalone.
|
void
|
setVersion(java.lang.String xmlVersion)
Sets the XML version of this Document from the XML prolog declaration (e.g.
|
Methods inherited from class com.ibm.xml.parser.Parent
|
addElement, elements, getChildNodes, getChildrenArray, getFirstChild, hasChildNodes, insert, insertAfter, insertBefore, insertFirst, insertLast, removeChild, replaceChild |
Methods inherited from class com.ibm.xml.parser.Child
|
clearDigest, clone, getChildNodes, getDigest, getFactory, getFirstChild, getNextSibling, getParentNode, getPreviousSibling, getText, hasChildNodes, insertBefore, makeXPointer, print, print, removeChild, replaceChild, searchAncestors, searchAncestors, setFactory, toXMLString, toXMLString |
Methods inherited from class java.lang.Object
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
TXDocument
public TXDocument()
- Constructor. Adds the
xml
namespace to this document.
clone
public java.lang.Object clone()
- Clone this Document Node and its children using the appropriate factories.
This method is defined by Child.
- Returns:
- Cloned Document Node and all children.
- Overrides:
- clone in class Child
- See Also:
- clone
getNodeType
public int getNodeType()
- Returns that this object is a Document Node.
This method is defined by DOM.
- Returns:
- Document Node indicator.
getContextInfo
public DocumentContext getContextInfo()
- Returns this Document's document context.
- Implements:
- getContextInfo in interface Document
- Returns:
- Document context, or null if no type.
- See Also:
- setContextInfo, com.ibm.xml.parser.DocumentContext
setContextInfo
public void setContextInfo(DocumentContext documentContext)
- Sets this Document's document context.
- Implements:
- setContextInfo in interface Document
- Parameters:
documentContext
- Document context.
- See Also:
- setContextInfo, com.ibm.xml.parser.DocumentContext
getDocumentElement
public Element getDocumentElement()
- Returns this Document's root Element.
- Implements:
- getDocumentElement in interface Document
- Returns:
- Document root Element, or null if no root Element.
- See Also:
- setDocumentElement, getRootName
setDocumentElement
public void setDocumentElement(Element rootElement)
- Sets this Document's root Element.
- Implements:
- setDocumentElement in interface Document
- Returns:
- Document root Element.
- See Also:
- getDocumentElement
getRootName
public java.lang.String getRootName()
- Returns the name of this Document's root Element (not DTD).
- Returns:
- Name of Document root Element, or null if no root element.
- See Also:
- getDocumentElement
getElementsByTagName
public NodeIterator getElementsByTagName(java.lang.String qName)
- Returns a NodeIterator of matches through all child Element Nodes.
Searching is done recursively, not just for immediate Child Nodes.
The returned iterator is not "live" (refer to VectorNodeIterator for details).
The specified qualified name refers to the Element tag name (see Namespace for details).
This method is defined by DOM.
- Implements:
- getElementsByTagName in interface Document
- Parameters:
qName
- Qualified name to match against in all subordinate Elements.
- Returns:
- A NodeIterator of matched Element Nodes (TXElement).
If no matches, an empty iterator is returned.
- See Also:
- getElementsByTagName, com.ibm.xml.parser.VectorNodeIterator, Namespace
getDocumentType
public Node getDocumentType()
- Returns this Document's Type Definition (DTD) as a Node.
- Implements:
- getDocumentType in interface Document
- Returns:
- Document Type Definition (DTD), or null if no type.
- See Also:
- getDTD, setDocumentType
getDTD
public DTD getDTD()
- Returns this Document's Type Definition (DTD) as a DTD.
- Returns:
- Document Type Definition (DTD), or null if no type.
- See Also:
- getDocumentType, isApplySyntax, setDocumentType
setDocumentType
public void setDocumentType(Node documentType)
- Sets this Document's Type Definition (DTD).
- Implements:
- setDocumentType in interface Document
- Parameters:
documentType
- Document Type Definition (DTD) in the form of a Node.
- See Also:
- getDocumentType, getDTD, isApplySyntax
isApplySyntax
public boolean isApplySyntax()
- Returns whether a syntax is being applied to this doument. In other words,
return whether a Document Type Definition (DTD) has been defined.
- Returns:
- =true if a Document Type Definition (DTD) has been defined; otherwise =false.
- See Also:
- getDocumentType, getDTD, setDocumentType
getStandalone
public java.lang.String getStandalone()
- Returns if this Document is standalone. A document that contains a standalone value
of yes indicates that there are no markup declarations external to the document
entity either in the DTD external subset, or in an external parameter entity
referenced from the internal subset. The value no indicates that there
are or may be such external markup declarations.
- Returns:
- =yes if standalone; =no if not standalone;
=null if not known.
- See Also:
- setStandalone, isStandalone
isStandalone
public boolean isStandalone()
- Returns if this Document is standalone. A document that contains a standalone value
of true indicates that there are no markup declarations external to the document
entity either in the DTD external subset, or in an external parameter entity
referenced from the internal subset. The value false indicates that there
are or may be such external markup declarations.
- Returns:
- =true if standalone; otherwise, =false.
- See Also:
- getStandalone, setStandalone
setStandalone
public void setStandalone(java.lang.String standalone)
- Sets if this Document is standalone. A document that contains a standalone value
of yes indicates that there are no markup declarations external to the document
entity either in the DTD external subset, or in an external parameter entity
referenced from the internal subset. The value no indicates that there
are or may be such external markup declarations.
- Returns:
- =yes if standalone; =no if not standalone;
=null if not known.
- See Also:
- isStandalone, getStandalone
getVersion
public java.lang.String getVersion()
- Returns the XML version of this Document from the XML prolog declaration (e.g.
<?xml ...>
).
- Returns:
- XML version of this Document (e.g. "1.0"), or null if version not specified.
- See Also:
- setVersion
setVersion
public void setVersion(java.lang.String xmlVersion)
- Sets the XML version of this Document from the XML prolog declaration (e.g.
<?xml ...>
).
- Parameters:
xmlVersion
- XML version of this Document (e.g. "1.0").
- See Also:
- getVersion
getEncoding
public java.lang.String getEncoding()
- Returns the value of the XML encoding parameter from the XML prolog declaration (e.g.
<?xml encoding="...">
).
- Returns:
- Value of the XML encoding parameter, or null if encoding not specified.
- See Also:
- setEncoding
setEncoding
public void setEncoding(java.lang.String xmlEncoding)
- Sets the value of the XML encoding parameter from the XML prolog declaration (e.g.
<?xml encoding="...">
).
The supported XML encodings are the intersection of XML-supported code sets and
those supported in JDK 1.1:
- UTF-16
- ISO-10646-UCS-2
- ISO-10646-UCS-4
- UTF-8
- US-ASCII
- ISO-8859-1 ... ISO-8859-9
- ISO-2022-JP
- Shift_JIS
- EUC-JP
- GB2312
- Big5
- KSC5601
- ISO2022KR
- KOI8_R
- Parameters:
xmlEncoding
- Value of the XML encoding parameter.
- See Also:
- convert, getEncoding, setEncoding
getNamespaceFor
public NamespacePI getNamespaceFor(java.lang.String nsPrefixName)
- Returns the NamespacePI instance which matches the specified namespace prefix name.
- Parameters:
prefixName
- The prefix value to match from <?xml:namespace ns="..." prefix="...">
.
- Returns:
- Matching NamespacePI, or null if no match.
- See Also:
- getNamespaces, addNamespace, setNamespaceParameters, NamespacePI
getNamespaces
public java.util.Enumeration getNamespaces()
- Returns an enumeration of NamespacePI instances defined for this Document.
- Returns:
- All defined NamespacePI instances, or null none defined.
- See Also:
- getNamespaceFor, addNamespace, setNamespaceParameters, NamespacePI
addNamespace
public void addNamespace(NamespacePI namespacePI)
- Records the presence of a NamespacePI instance for this Document. Note
that this method does not add a Node for the NamespacePI. This method
facilitates a quick hash table query of defined namespaces.
This method is automatically called by insert
and addElement
methods.
- Parameters:
namespacePI
- The namespacePI instance to record.
- See Also:
- getNamespaces, getNamespaceFor, setNamespaceParameters, NamespacePI
setNamespaceParameters
public java.lang.String setNamespaceParameters(Namespace namespace)
- Returns the specified namespace with all aspects of its namespace set
according to NamespacePIs defined in this document, and the raw tag name.
- Parameters:
namespace
- Namespace to be initialized. Note: namespace.getName()
must contain the tag's qualified name.
- Returns:
- Error message, or
null
if successful. - See Also:
- getNamespaces, getNamespaceFor, addNamespace, Namespace, NamespacePI
insert
public void insert(Child child,
int index) throws LibraryException
- Insert a Child Node into the specified position. Special consideration is given
to DTDs, the root document Element, and namspace PI children.
- Parameters:
child
- The Child Node being inserted.
index
- 0-based index into the list of children.
- Throws:
- LibraryException - Thrown if the document's root element is set twice.
- Overrides:
- insert in class Parent
printWithFormat
public void printWithFormat(java.io.Writer pw) throws java.io.IOException, LibraryException
- Format and print this Node and any children in XML format using the default character
encoding.
- Parameters:
pw
- The character output stream to use.
- Throws:
- java.io.IOException - Thrown if a Node can not be visitted because of an invalid pw.
- LibraryException - Thrown if the document object hierarchy is in an unknown state.
- See Also:
- print
printWithFormat
public void printWithFormat(java.io.Writer pw,
java.lang.String encoding) throws java.io.IOException, LibraryException
- Format and print this Node and any children in XML format using the specified character
encoding.
- Parameters:
pw
- The character output stream to use.
encoding
- Java character encoding in use by pw.
- Throws:
- java.io.IOException - Thrown if a Node can not be visitted because of an invalid pw.
- LibraryException - Thrown if the document object hierarchy is in an unknown state.
- See Also:
- print
printWithFormat
public void printWithFormat(java.io.Writer pw,
java.lang.String encoding,
int indent) throws java.io.IOException, LibraryException
- Format and print this Node and any children in XML format, using the specified
character encoding, and indented by indent spaces.
- Parameters:
pw
- The character output stream to use.
encoding
- Java character encoding in use by pw.
indent
- Number of spaces to indent at each nesting level.
- Throws:
- java.io.IOException - Thrown if a Node can not be visitted because of an invalid pw.
- LibraryException - Thrown if the document object hierarchy is in an unknown state.
- See Also:
- print
setPrintInternalDTD
public void setPrintInternalDTD(boolean printInternalDTD)
- Sets whether the internal DTD is printed by the
print()
methods.
- Parameters:
printInternalDTD
- =true to print the internal DTD; =false to not print.
getText
public java.lang.String getText()
- Return all text associated with this Node and its children without considering entities.
This method is defined by Child.
- Returns:
- Text associated with all children, or "" if no children.
- Overrides:
- getText in class Child
- See Also:
- toXMLString
getMasterDoc
public Document getMasterDoc()
- Returns the Document Node asociated with this document fragment.
Note: XML4J has not yet implemented document fragments.
This method is CURRENTLY NOT IMPLEMENTED.
- Returns:
- Document Node associated with this document fragment.
- See Also:
- setMasterDoc
setMasterDoc
public void setMasterDoc(Document document)
- Sets the Document Node asociated with this document fragment.
Note: XML4J has not yet implemented document fragments.
This method is CURRENTLY NOT IMPLEMENTED.
- Parameters:
document
- Document Node associated with this document fragment.
- See Also:
- getMasterDoc
createDocumentContext
public DocumentContext createDocumentContext()
- Create and return a new DocumentContext.
It should be noted this factory method is not used by the parser.
This method is defined by DOM.
- Implements:
- createDocumentContext in interface Document
- Returns:
- New TXDocumentContext Node.
createElement
public Element createElement(java.lang.String tagName,
AttributeList attributes)
- Create and return a new Element Node.
It should be noted this factory method is not used by the parser.
This method is defined by DOM.
- Implements:
- createElement in interface Document
- Parameters:
tagName
- The Element's tag name.
attributes
- The attributes to set specified in the form of a TXAttributeList or AttributeList.
Specify null if no attributes are to be set for the Element.
- Returns:
- New TXElement Node.
createTextNode
public Text createTextNode(java.lang.String data)
- Create and return a new Text Node.
It should be noted this factory method is not used by the parser.
This method is defined by DOM.
- Implements:
- createTextNode in interface Document
- Parameters:
data
- The actual content of the text Node.
- Returns:
- New TXText Node.
createComment
public Comment createComment(java.lang.String data)
- Create and return a new Comment Node.
It should be noted this factory method is not used by the parser.
This method is defined by DOM.
- Implements:
- createComment in interface Document
- Parameters:
data
- The actual content of the comment Node.
- Returns:
- New TXComment Node.
createPI
public PI createPI(java.lang.String name,
java.lang.String data)
- Create and return a new PI Node.
It should be noted this factory method is not used by the parser.
This method is defined by DOM.
- Implements:
- createPI in interface Document
- Parameters:
name
- The first token following the markup.
data
- From the character immediately after the name to the character immediately preceding the ?>
.
- Returns:
- New TXPI Node.
createAttribute
public Attribute createAttribute(java.lang.String name,
Node value)
- Create and return a new Attribute.
It should be noted this factory method is not used by the parser.
This method is defined by DOM.
- Implements:
- createAttribute in interface Document
- Parameters:
name
- The name of this attribute.
value
- This parameter IS NOT IMPLEMENTED.
- Returns:
- New TXAttribute.
createAttributeList
public AttributeList createAttributeList()
- Create and return a new AttributeList.
It should be noted this factory method is not used by the parser.
This method is defined by DOM.
- Implements:
- createAttributeList in interface Document
- Returns:
- New TXAttributeList.
createTreeIterator
public TreeIterator createTreeIterator(Node node)
- Note: createTreeIterator() is deprecated.Not implemented.
- Implements:
- createTreeIterator in interface Document
acceptPre
public void acceptPre(Visitor visitor) throws java.lang.Exception
- Implements the accept operation of the visitor design pattern when the start of
a TXDocument Node is recognized when traversing the document object tree.
- Parameters:
visitor
- The implemention of the Visitor operation (toXMLString, digest, ...)
- Throws:
- java.lang.Exception - Thrown if this Node can not be visitted, or traversal modification is requested.
- See Also:
- Visitor, TreeTraversal, NonRecursivePreorderTreeTraversal, TreeTraversalException
acceptPost
public void acceptPost(Visitor visitor) throws java.lang.Exception
- Implements the accept operation of the visitor design pattern when the end of
a TXDocument Node is recognized when traversing the document object tree.
- Parameters:
visitor
- The implemention of the Visitor operation (toXMLString, digest, ...)
- Throws:
- java.lang.Exception - Thrown if this Node can not be visitted, or traversal modification is requested.
- See Also:
- Visitor, TreeTraversal, NonRecursivePreorderTreeTraversal, TreeTraversalException