#include <DomDocument.h>
Inherits xmldom::DomNode.
Inheritance diagram for xmldom::DomDocument:
DomDocument
interface represents the entire XML document.
Conceptually, it is the root of the document tree, and provides the primary access to the document's data.
Since elements, text nodes, comments, processing instructions, etc. cannot exist outside the context of a DomDocument
, the DomDocument
interface also contains the factory methods needed to create these objects. The DomNode
objects created have a getOwnerDocument()
attribute which associates them with the DomDocument
within whose context they were created.
Public Member Functions | |
DomDocument () | |
ctor | |
DomDocument (const DomDocument ©) | |
copy ctor | |
virtual | ~DomDocument () |
dtor | |
const DomDocument & | operator= (const DomDocument &assign) |
assign | |
DOM Level 1 | |
DomElement | createElement (const DomString &tagName) |
Creates an element of the type specified. | |
DomDocumentFragment | createDocumentFragment () |
Creates an empty DomDocumentFragment object. | |
DomText | createTextNode (const DomString &data) |
Creates a DomText node given the specified string. | |
DomComment | createComment (const DomString &data) |
Creates a DomComment node given the specified string. | |
DomCDATASection | createCDATASection (const DomString &data) |
Creates a DomCDATASection node whose value is the specified string. | |
DomProcessingInstruction | createProcessingInstruction (const DomString &target, const DomString &data) |
Creates a DomProcessingInstruction node given the specified name and data strings. | |
DomAttribute | createAttribute (const DomString &name) |
Creates an DomAttribute of the given name. | |
DomEntityReference | createEntityReference (const DomString &name) |
Creates an DomEntityReference object. | |
DomDocumentType | getDocumentType () const |
The Document Type Declaration (see DomDocumentType) associated with this document. | |
DomElement | getDocumentElement () const |
This is a convenience attribute that allows direct access to the child node that is the document element of the document. | |
DomNodeList | getElementsByTagName (const DomString &tagName) const |
Returns a DomNodeList of all the DomElements in document order with a given tag name and are contained in the document. | |
DOM Level 2 | |
DomElement | createElementNS (const DomString &namespaceURI, const DomString &qualifiedName) |
Creates an element of the given qualified name and namespace URI. | |
DomAttribute | createAttributeNS (const DomString &namespaceURI, const DomString &qualifiedName) |
Creates an attribute of the given qualified name and namespace URI. | |
DomNodeList | getElementsByTagNameNS (const DomString &namespaceURI, const DomString &localName) const |
Returns a DomNodeList of all the DomElements with a given local name and namespace URI" in document order. | |
DomElement | getElementById (const DomString &elementId) const |
Returns the DomElement that has an ID attribute with the given value. | |
DOM Level 3 | |
DomString | getInputEncoding () const |
An attribute specifying the encoding used for this document at the time of the parsing. | |
DomString | getXmlEncoding () const |
An attribute specifying, as part of the XML declaration, the encoding of this document. | |
bool | isXmlStandalone () const |
An attribute specifying, as part of the XML declaration, whether this document is standalone. | |
void | setXmlStandalone (bool standalone) |
Set if this document is standalone. | |
DomString | getXmlVersion () const |
An attribute specifying, as part of the XML declaration, the version number of this document. | |
void | setXmlVersion (const DomString &version) |
Set the XML version. | |
bool | isStrictErrorChecking () const |
An attribute specifying whether error checking is enforced or not. | |
void | setStrictErrorChecking (bool strictErrorChecking) |
Set the strict error checking. | |
DomString | getDocumentURI () const |
Get the location of the document or null if undefined or if the DOmDocument was created using DomImplementation::createDocument(). | |
void | setDocumentURI (const DomString &documentURI) |
Set the location of the document. | |
DomNode | adoptNode (const DomNode &source) |
Attempts to adopt a node from another document to this document. | |
DomConfiguration | getDomConfiguration () const |
The configuration used when DomDocument::normalizeDocument() is invoked. | |
void | normalizeDocument () |
This method acts as if the document was going through a save and load cycle, putting the document in a "normal" form. | |
DomNode | renameNode (const DomNode &node, const DomString &namespaceURI, const DomString &name) |
Rename an existing node of type ElementNode or AttributeNode . | |
Static Public Member Functions | |
Extensions to the Standard | |
static DomDocument | createFromURI (const DomString &uri) |
Create a new DomDocument from the XML document specified by the given URI. | |
static DomDocument | createFromString (const DomString &document) |
Create a new DomDocument from the XML document specified by the given string. |
xmldom::DomDocument::DomDocument | ( | ) |
ctor
xmldom::DomDocument::DomDocument | ( | const DomDocument & | copy | ) |
copy ctor
xmldom::DomDocument::~DomDocument | ( | ) | [virtual] |
dtor
const DomDocument & xmldom::DomDocument::operator= | ( | const DomDocument & | assign | ) |
assign
DomElement xmldom::DomDocument::createElement | ( | const DomString & | tagName | ) |
Creates an element of the type specified.
Note that the instance returned implements the DomElement interface, so attributes can be specified directly on the returned object. In addition, if there are known attributes with default values, DomAttribute nodes representing them are automatically created and attached to the element.
To create an element with a qualified name and namespace URI, use the createElementNS() method.
tagName | The name of the element type to instantiate. For XML, this is case-sensitive, otherwise it depends on the case-sensitivity of the markup language in use. In that case, the name is mapped to the canonical form of that markup by the DOM implementation. |
tagName
, and getLocalName(), getPrefix(), and getNamespaceURI() set to null. DomDocumentFragment xmldom::DomDocument::createDocumentFragment | ( | ) |
Creates a DomText node given the specified string.
dataThe | data for the node. |
DomComment xmldom::DomDocument::createComment | ( | const DomString & | data | ) |
Creates a DomComment node given the specified string.
data | The data for the node. |
DomCDATASection xmldom::DomDocument::createCDATASection | ( | const DomString & | data | ) |
Creates a DomCDATASection node whose value is the specified string.
data | The data for the DomCDATASection contents. |
DomProcessingInstruction xmldom::DomDocument::createProcessingInstruction | ( | const DomString & | target, | |
const DomString & | data | |||
) |
Creates a DomProcessingInstruction node given the specified name and data strings.
target | The target part of the processing instruction. Unlike createElementNS() or createAttributeNS(), no namespace well-formed checking is done on the target name. Applications should invoke normalizeDocument() with the parameter "namespaces" set to true in order to ensure that the target name is namespace well-formed. | |
The | data for the node. |
DomAttribute xmldom::DomDocument::createAttribute | ( | const DomString & | name | ) |
Creates an DomAttribute of the given name.
Note that the DomAttribute instance can then be set on an DomElement using the setAttributeNode() method.
To create an attribute with a qualified name and namespace URI, use the createAttributeNS() method.
name | The name of the attribute. |
DomEntityReference xmldom::DomDocument::createEntityReference | ( | const DomString & | name | ) |
Creates an DomEntityReference object.
In addition, if the referenced entity is known, the child list of the DomEntityReference node is made the same as that of the corresponding DomEntity node.
name | The name of the entity to reference. Unlike createElementNS() or createAttributeNS(), no namespace well-formed checking is done on the entity name. Applications should invoke normalizeDocument() with the parameter "namespaces" set to true in order to ensure that the entity name is namespace well-formed. |
DomDocumentType xmldom::DomDocument::getDocumentType | ( | ) | const |
The Document Type Declaration (see DomDocumentType) associated with this document.
For XML documents without a document type declaration this returns null. For HTML documents, a DomDocumentType object may be returned, independently of the presence or absence of document type declaration in the HTML document. This provides direct access to the DomDocumentType node, child node of this DomDocument. This node can be set at document creation time and later changed through the use of child nodes manipulation methods, such as DomNode::insertBefore(), or DomNode::replaceChild(). Note, however, that while some implementations may instantiate different types of DomDocument objects supporting additional features than the "Core", such as "HTML" [DOM Level 2 HTML], based on the DomDocumentType specified at creation time, changing it afterwards is very unlikely to result in a change of the features supported.
DomElement xmldom::DomDocument::getDocumentElement | ( | ) | const |
This is a convenience attribute that allows direct access to the child node that is the document element of the document.
DomNodeList xmldom::DomDocument::getElementsByTagName | ( | const DomString & | tagName | ) | const |
Returns a DomNodeList of all the DomElements in document order with a given tag name and are contained in the document.
tagname | The name of the tag to match on. The special value "*" matches all tags. For XML, the tagname parameter is case-sensitive, otherwise it depends on the case-sensitivity of the markup language in use. |
DomElement xmldom::DomDocument::createElementNS | ( | const DomString & | namespaceURI, | |
const DomString & | qualifiedName | |||
) |
Creates an element of the given qualified name and namespace URI.
Per [XML Namespaces], applications must use the value null as the namespaceURI
parameter for methods if they wish to have no namespace.
namespaceURI | The namespace URI of the element to create. | |
qualifiedName | The qualified name of the element type to instantiate. |
DomAttribute xmldom::DomDocument::createAttributeNS | ( | const DomString & | namespaceURI, | |
const DomString & | qualifiedName | |||
) |
Creates an attribute of the given qualified name and namespace URI.
Per [XML Namespaces], applications must use the value null as the namespaceURI
parameter for methods if they wish to have no namespace.
namespaceURI | The namespace URI of the attribute to create. | |
qualifiedName | The qualified name of the attribute to instantiate. |
DomNodeList xmldom::DomDocument::getElementsByTagNameNS | ( | const DomString & | namespaceURI, | |
const DomString & | localName | |||
) | const |
Returns a DomNodeList of all the DomElements with a given local name and namespace URI" in document order.
namespaceURI | The ref glossaryNamespaceURI "namespace URI" of the elements to match on. The special value "*" matches all namespaces. | |
localName | The local name of the elements to match on. The special value "*" matches all local names. |
DomElement xmldom::DomDocument::getElementById | ( | const DomString & | elementId | ) | const |
Returns the DomElement that has an ID attribute with the given value.
If no such element exists, this returns null. If more than one element has an ID attribute with that value, what is returned is undefined.
The DOM implementation is expected to use the attribute DomAttribute::isId() to determine if an attribute is of type ID.
elementId | The unique id value for an element. |
DomString xmldom::DomDocument::getInputEncoding | ( | ) | const |
An attribute specifying the encoding used for this document at the time of the parsing.
This is null when it is not known, such as when the DomDocument was created in memory.
xmldom::DomString xmldom::DomDocument::getXmlEncoding | ( | ) | const |
An attribute specifying, as part of the XML declaration, the encoding of this document.
This is null when unspecified or when it is not known, such as when the DomDocument was created in memory.
bool xmldom::DomDocument::isXmlStandalone | ( | ) | const |
An attribute specifying, as part of the XML declaration, whether this document is standalone.
This is false when unspecified.
void xmldom::DomDocument::setXmlStandalone | ( | bool | standalone | ) |
Set if this document is standalone.
Set isXmlStandalone() for details.
DomString xmldom::DomDocument::getXmlVersion | ( | ) | const |
An attribute specifying, as part of the XML declaration, the version number of this document.
If there is no declaration and if this document supports the "XML" feature, the value is "1.0". If this document does not support the "XML" feature, the value is always null. Changing this attribute will affect methods that check for invalid characters in XML names. Application should invoke DomDocument::normalizeDocument() in order to check for invalid characters in the DomNode that are already part of this DomDocument.
DOM applications may use the DomImplementation::hasFeature() method with parameter values "XMLVersion" and "1.0" (respectively) to determine if an implementation supports [XML 1.0]. DOM applications may use the same method with parameter values "XMLVersion" and "1.1" (respectively) to determine if an implementation supports [XML 1.1]. In both cases, in order to support XML, an implementation must also support the "XML" feature defined in this specification. DomDocument objects supporting a version of the "XMLVersion" feature must not raise a NotSupportedErr exception for the same version number when using DomDocument::getXmlVersion().
void xmldom::DomDocument::setXmlVersion | ( | const DomString & | version | ) |
Set the XML version.
See getXmlVersion() for details.
bool xmldom::DomDocument::isStrictErrorChecking | ( | ) | const |
An attribute specifying whether error checking is enforced or not.
When set to false, the implementation is free to not test every possible error case normally defined on DOM operations, and not raise any DomException on DOM operations or report errors while using DomDocument::normalizeDocument(). In case of error, the behavior is undefined. This attribute is true by default.
void xmldom::DomDocument::setStrictErrorChecking | ( | bool | strictErrorChecking | ) |
Set the strict error checking.
Set isStrictErrorChecking() for details.
DomString xmldom::DomDocument::getDocumentURI | ( | ) | const |
Get the location of the document or null if undefined or if the DOmDocument was created using DomImplementation::createDocument().
No lexical checking is performed when setting this attribute; this could result in a null value returned when using DomNode::getBaseURI().
Beware that when the DomDocument supports the feature "HTML" [DOM Level 2 HTML], the href attribute of the HTML BASE element takes precedence over this attribute when computing DomNode::getBaseURI().
void xmldom::DomDocument::setDocumentURI | ( | const DomString & | documentURI | ) |
Set the location of the document.
See getDocumentURI() for details.
Attempts to adopt a node from another document to this document.
If supported, it changes the getOwnerDocument() of the source node, its children, as well as the attached attribute nodes if there are any. If the source node has a parent it is first removed from the child list of its parent. This effectively allows moving a subtree from one document to another (unlike importNode() which create a copy of the source node instead of moving it).
When it fails, applications should use DomDocument::importNode() instead. Note that if the adopted node is already part of this document (i.e. the source and target document are the same), this method still has the effect of removing the source node from the child list of its parent, if any. The following list describes the specifics for each type of node.
source | The node to move into this document. |
DomConfiguration xmldom::DomDocument::getDomConfiguration | ( | ) | const |
The configuration used when DomDocument::normalizeDocument() is invoked.
void xmldom::DomDocument::normalizeDocument | ( | ) |
This method acts as if the document was going through a save and load cycle, putting the document in a "normal" form.
As a consequence, this method updates the replacement tree of DomEntityReference nodes and normalizes DomText nodes, as defined in the method DomNode::normalize().
Otherwise, the actual result depends on the features being set on the DomDocument::getDomConfiguration() object and governing what operations actually take place. Noticeably this method could also make the document namespace well-formed according to the algorithm described in Namespace Normalization, check the character normalization, remove the DomCDATASection nodes, etc. See DomConfiguration for details.
// Keep in the document the information defined // in the XML Information Set (Java example) DOMConfiguration docConfig = myDocument.getDomConfig(); docConfig.setParameter("infoset", Boolean.TRUE); myDocument.normalizeDocument();
Mutation events, when supported, are generated to reflect the changes occurring on the document.
If errors occur during the invocation of this method, such as an attempt to update a read-only node or a DomNode::getNodeName() contains an invalid character according to the XML version in use, errors or warnings (DomError::SeverityError or DomError::SeverityWarning) will be reported using the DomErrorHandler object associated with the "error-handler" parameter. Note this method might also report fatal errors (DomError::SeverityFatalError) if an implementation cannot recover from an error.
DomNode xmldom::DomDocument::renameNode | ( | const DomNode & | node, | |
const DomString & | namespaceURI, | |||
const DomString & | name | |||
) |
Rename an existing node of type ElementNode
or AttributeNode
.
When possible this simply changes the name of the given node, otherwise this creates a new node with the specified name and replaces the existing node with the new node as described below.
If simply changing the name of the given node is not possible, the following operations are performed: a new node is created, any registered event listener is registered on the new node, any user data attached to the old node is removed from that node, the old node is removed from its parent if it has one, the children are moved to the new node, if the renamed node is an DomElement its attributes are moved to the new node, the new node is inserted at the position the old node used to have in its parents child nodes list if it has one, the user data that was attached to the old node is attached to the new node. When the node being renamed is an DomElement only the specified attributes are moved, default attributes originated from the DTD are updated according to the new element name. In addition, the implementation may update default attributes from other schemas. Applications should use normalizeDocument() to guarantee these attributes are up-to-date.
When the node being renamed is an DomAttribute that is attached to an DomElement, the node is first removed from the DomElement attributes map. Then, once renamed, either by modifying the existing node or creating a new one as described above, it is put back. In addition,
NodeRenamed
is fired,
node | The node to rename. | |
namespaceURI | The new namespace URI. | |
qualifiedName | The new qualified name. |
DomDocument xmldom::DomDocument::createFromURI | ( | const DomString & | uri | ) | [static] |
Create a new DomDocument from the XML document specified by the given URI.
The default implementation is taken with the default feature set.
uri | The URI from where to get the document. |
DomDocument xmldom::DomDocument::createFromString | ( | const DomString & | document | ) | [static] |
Create a new DomDocument from the XML document specified by the given string.
The default implementation is taken with the default feature set.
document | A string with the XML document. |