[][src]Trait xml_dom::level2::Document

pub trait Document: Node {
    fn doc_type(&self) -> Option<Self::NodeRef>;
fn document_element(&self) -> Option<Self::NodeRef>;
fn implementation(&self) -> &dyn DOMImplementation<NodeRef = Self::NodeRef>;
fn create_attribute(&self, name: &str) -> Result<Self::NodeRef>;
fn create_attribute_with(
        &self,
        name: &str,
        value: &str
    ) -> Result<Self::NodeRef>;
fn create_attribute_ns(
        &self,
        namespace_uri: &str,
        qualified_name: &str
    ) -> Result<Self::NodeRef>;
fn create_cdata_section(&self, data: &str) -> Result<Self::NodeRef>;
fn create_document_fragment(&self) -> Result<Self::NodeRef>;
fn create_entity_reference(&self, name: &str) -> Result<Self::NodeRef>;
fn create_comment(&self, data: &str) -> Self::NodeRef;
fn create_element(&self, tag_name: &str) -> Result<Self::NodeRef>;
fn create_element_ns(
        &self,
        namespace_uri: &str,
        qualified_name: &str
    ) -> Result<Self::NodeRef>;
fn create_processing_instruction(
        &self,
        target: &str,
        data: Option<&str>
    ) -> Result<Self::NodeRef>;
fn create_text_node(&self, data: &str) -> Self::NodeRef;
fn get_element_by_id(&self, id: &str) -> Option<Self::NodeRef>;
fn get_elements_by_tag_name(&self, tag_name: &str) -> Vec<Self::NodeRef>;
fn get_elements_by_tag_name_ns(
        &self,
        namespace_uri: &str,
        local_name: &str
    ) -> Vec<Self::NodeRef>; }

This corresponds to the DOM Document interface.

Required methods

fn doc_type(&self) -> Option<Self::NodeRef>

The Document Type Declaration (see DocumentType) associated with this document.

Specification

For HTML documents as well as XML documents without a document type declaration this returns null. The DOM Level 2 does not support editing the Document Type Declaration. docType cannot be altered in any way, including through the use of methods inherited from the Node interface, such as insertNode or removeNode.

fn document_element(&self) -> Option<Self::NodeRef>

This is a convenience attribute that allows direct access to the child node that is the root element of the document.

Specification

For HTML documents, this is the element with the tagName "HTML".

fn implementation(&self) -> &dyn DOMImplementation<NodeRef = Self::NodeRef>

The DOMImplementation object that handles this document.

Note: this function will panic if for some reason an implementation is not associated with the document instance.

Specification

A DOM application may use objects from multiple implementations.

fn create_attribute(&self, name: &str) -> Result<Self::NodeRef>

Creates an Attribute of the given name. Note that the Attr instance can then be set on an Element using the setAttributeNode method.

Specification

To create an attribute with a qualified name and namespace URI, use the createAttributeNS method.

Parameters

  • name of type DOMString: The name of the attribute.

Return Value

  • Attr: A new Attr object with the nodeName attribute set to name, and localName, prefix, and namespaceURI set to null. The value of the attribute is the empty string.

Exceptions

  • INVALID_CHARACTER_ERR: Raised if the specified name contains an illegal character.

fn create_attribute_with(
    &self,
    name: &str,
    value: &str
) -> Result<Self::NodeRef>

Implementation defined extension: this is the same as create_attribute except that it also sets the attribute value.

fn create_attribute_ns(
    &self,
    namespace_uri: &str,
    qualified_name: &str
) -> Result<Self::NodeRef>

Creates an attribute of the given qualified name and namespace URI.

Specification

HTML-only DOM implementations do not need to implement this method.

Parameters

  • namespaceURI of type DOMString: The namespace URI of the attribute to create.
  • qualifiedName of type DOMString: The qualified name of the attribute to instantiate.

Return Value

  • Attr: A new Attr object with the following attributes:
AttributeValue
Node.nodeNamequalifiedName
Node.namespaceURInamespaceURI
Node.prefixprefix, extracted from qualifiedName, or null if there is no prefix
Node.localNamelocal name, extracted from qualifiedName
Attr.namequalifiedName
Node.nodeValuethe empty string

Exceptions

  • INVALID_CHARACTER_ERR: Raised if the specified qualified name contains an illegal character.
  • NAMESPACE_ERR: Raised if the qualifiedName is malformed, if the qualifiedName has a prefix and the namespaceURI is null, if the qualifiedName has a prefix that is "xml" and the namespaceURI is different from "http://www.w3.org/XML/1998/namespace", or if the qualifiedName is "xmlns" and the namespaceURI is different from "http://www.w3.org/2000/xmlns/".

fn create_cdata_section(&self, data: &str) -> Result<Self::NodeRef>

Creates a CDataSection node whose value is the specified string.

Specification

Parameters

  • data of type DOMString: The data for the CDATASection contents.

Return Value

  • CDATASection: The new CDATASection object.

Exceptions

  • NOT_SUPPORTED_ERR: Raised if this document is an HTML document.

fn create_document_fragment(&self) -> Result<Self::NodeRef>

Creates an empty DocumentFragment object.

Specification

Return Value

DocumentFragment: A new DocumentFragment.

fn create_entity_reference(&self, name: &str) -> Result<Self::NodeRef>

Creates an EntityReference object.

Specification

In addition, if the referenced entity is known, the child list of the EntityReference node is made the same as that of the corresponding Entity node.

Note: If any descendant of the Entity node has an unbound namespace prefix, the corresponding descendant of the created EntityReference node is also unbound; (its namespaceURI is null). The DOM Level 2 does not support any mechanism to resolve namespace prefixes.

Parameters

  • name of type DOMString: The name of the entity to reference.

Return Value

  • EntityReference: The new EntityReference object.

Exceptions

  • INVALID_CHARACTER_ERR: Raised if the specified name contains an illegal character.
  • NOT_SUPPORTED_ERR: Raised if this document is an HTML document.

fn create_comment(&self, data: &str) -> Self::NodeRef

Creates a Comment node given the specified string.

Specification

Parameters

  • data of type DOMString: The data for the node.

Return Value

  • Comment: The new Comment object.

fn create_element(&self, tag_name: &str) -> Result<Self::NodeRef>

Creates an element of the type specified.

Specification

Note that the instance returned implements the Element interface, so attributes can be specified directly on the returned object.

In addition, if there are known attributes with default values, Attr 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.

Parameters

  • tagName of type DOMString: The name of the element type to instantiate. For XML, this is case-sensitive. For HTML, the tagName` parameter may be provided in any case, but it must be mapped to the canonical uppercase form by the DOM implementation.

Return Value

  • Element: A new Element object with the nodeName attribute set to tagName, and localName, prefix, and namespaceURI set to null.

Exceptions

  • INVALID_CHARACTER_ERR: Raised if the specified name contains an illegal character.

fn create_element_ns(
    &self,
    namespace_uri: &str,
    qualified_name: &str
) -> Result<Self::NodeRef>

Creates an element of the given qualified name and namespace URI.

Specification

HTML-only DOM implementations do not need to implement this method.

Parameters

  • namespaceURI of type DOMString: The namespace URI of the attribute to create.
  • qualifiedName of type DOMString: The qualified name of the attribute to instantiate.

Return Value

  • Element: A new Element object with the following attributes:
AttributeValue
Node.nodeNamequalifiedName
Node.namespaceURInamespaceURI
Node.prefixprefix, extracted from qualifiedName, or null if there is no prefix
Node.localNamelocal name, extracted from qualifiedName
Attr.namequalifiedName
Node.nodeValuethe empty string

Exceptions

  • INVALID_CHARACTER_ERR: Raised if the specified qualified name contains an illegal character.
  • NAMESPACE_ERR: Raised if the qualifiedName is malformed, if the qualifiedName has a prefix and the namespaceURI is null, if the qualifiedName has a prefix that is "xml" and the namespaceURI is different from "http://www.w3.org/XML/1998/namespace", or if the qualifiedName is "xmlns" and the namespaceURI is different from "http://www.w3.org/2000/xmlns/".

fn create_processing_instruction(
    &self,
    target: &str,
    data: Option<&str>
) -> Result<Self::NodeRef>

Creates a ProcessingInstruction node given the specified name and data strings.

Specification

Parameters

  • target of type DOMString: The target part of the processing instruction.
  • data of type DOMString: The data for the node.

Return Value

  • ProcessingInstruction: The new ProcessingInstruction object.

Exceptions

  • INVALID_CHARACTER_ERR: Raised if the specified target contains an illegal character.
  • NOT_SUPPORTED_ERR: Raised if this document is an HTML document.

fn create_text_node(&self, data: &str) -> Self::NodeRef

Creates a Text node given the specified string.

Specification

Parameters

  • data of type DOMString: The data for the node.

Return Value

  • Text: The new Text object.

fn get_element_by_id(&self, id: &str) -> Option<Self::NodeRef>

Returns the Element whose ID is given by elementId.

Note: This implementation will ensure that attributes named xml:id or id with the XML namespace will be treated as identifiers. If the ProcessingOptions::set_assume_ids method is used when constructing a document any attribute with the local name id will be treated as identifiers.

Specification

If no such element exists, returns null. Behavior is not defined if more than one element has this ID.

Note: The DOM implementation must have information that says which attributes are of type ID. Attributes with the name "ID" are not of type ID unless so defined. Implementations that do not know whether attributes are of type ID or not are expected to return null.

Parameters

  • elementId of type DOMString: The unique id value for an element.

Return Value

  • Element: The matching element.

fn get_elements_by_tag_name(&self, tag_name: &str) -> Vec<Self::NodeRef>

Returns a NodeList of all the Elements with a given tag name in the order in which they are encountered in a preorder traversal of the Document tree.

Note: This method will panic if document_element is not an Element node.

Specification

Parameters

  • tagname of type DOMString: The name of the tag to match on. The special value "*" matches all tags.

Return Value

  • NodeList: A new NodeList object containing all the matched Elements.

fn get_elements_by_tag_name_ns(
    &self,
    namespace_uri: &str,
    local_name: &str
) -> Vec<Self::NodeRef>

Returns a NodeList of all the Elements with a given local name and namespace URI in the order in which they are encountered in a preorder traversal of the Document tree.

Note: This method will panic if document_element is not an Element node.

Specification

Parameters

  • namespaceURI of type DOMString: The namespace URI of the elements to match on. The special value "*" matches all namespaces.
  • localName of type DOMString: The local name of the elements to match on. The special value "*" matches all local names.

Return Value

  • NodeList: A new NodeList object containing all the matched Elements.
Loading content...

Implementors

impl Document for RefNode[src]

Loading content...