Xml Node

All the node types listed in the previous section are ultimately derived from the abstract XmlNode class, and it is this class that provides most of the functionality that you need when working with DOM trees.

Note that the XmlDocument class also inherits from XmlNode, so that it has all the methods and properties of a node. Because the XmlNode class is so important, I'll start by listing some of the properties and methods of the class in Tables 5.6 and 5.7.

Table 5.6: Impipiprtali Bass

Property

Description

Attribute

Returns an XmlAttributeCollection object containing the attributes of this node.

ChildNodes

Returns an XmlNodeList that contains all the children of this node.

FirstChild

Returns the first child of this node, or null if there are no children.

HasChildNodes

Returns true if this node has children.

Item

Retrieves a specified child node.

LastChild

Returns the last child of this node.

Name, LocalName

Returns the name of the node with or without a namespace prefix.

NextSibling, PreviousSibling

Returns the node immediately following or preceding this node.

NodeType

Returns the type of the node.

OwnerDocument

Returns the XmlDocument to which this node belongs.

ParentNode

Returns the parent of this node. What this returns depends on the node type.

Value

Gets or sets the value of this node. What the value is depends on the node type.

Table 5.7: IfiliMAitti

Method

Description

AppendChild, PrependChild

Adds a node to the end or beginning of the list of children for this node

Clone

Clones this node and all its children

CloneNode

Clones this node, choosing whether to include children

CreateNavigator

Creates an XPathNavigator to work with this node and its children

GetEnumerator

Gets an enumerator for a collection of nodes

InsertBefore, InsertAfter

Inserts a node before or after another node

Normalize

Normalizes the node by structuring the node and its children so that there are no adjacent text nodes

RemoveChild, RemoveAll

Removes one or all child nodes

ReplaceChild

Replaces one child node by another

SelectNodes, SelectSingleNode

Selects one or more nodes using an XPath expression

Supports

Tests whether the DOM implementation supports a feature

WriteContentTo

Writes the node content to an XmlWriter

Notice how many of these methods can be used to set up and modify hierarchies of nodes.

Notice how many of these methods can be used to set up and modify hierarchies of nodes.

0 0

Post a comment