C# Class HandCoded.Xml.NodeIndex

The NodeIndex class builds an index of the elements that comprise a DOM tree to allow subsequent queries to be efficiently executed.
A typical DOM document instance performs an expensive in-order traversal of the DOM tree every time the GetElementsByName method is called. This class does a one off traversal on construction and then uses the cached results to return XmlNodeList instances.

The NodeIndex also indexes 'id' attributes as the DOM has been found to be unreliable at indexing these during post parse schema validation.

Since TFP 1.2 the NodeIndex also attempts to capture schema type information for the XmlDocument as it explores it. Derivation relationships between types are determined and cached as calls to GetElementsByType are made.

Show file Open project: formicary/fpml-toolkit-csharp Class Usage Examples

Public Methods

Method Description
GetAttributesByName ( string name ) : XmlNodeList

Creates a (possibly empty) XmlNodeList containing all the attribute nodes identified by the given name string.

GetElementById ( string id ) : XmlElement

Returns the XmlElement in the indexed document that has an id attribute with the given value.

GetElementsByName ( string name ) : XmlNodeList

Creates a (possibly empty) XmlNodeList containing all the element nodes identified by the given name string.

GetElementsByType ( string ns, string type ) : XmlNodeList

Creates a (possibly empty) XmlNodeList containing all the element nodes of a given type (or a derived subtype).

NodeIndex ( XmlDocument document ) : System

Constructs a NodeIndex for the given XmlDocument.

Private Methods

Method Description
IndexNodes ( XmlNode node ) : void

Recursively walks a DOM tree creating an index of the elements by thier local name.

IsDerived ( XmlQualifiedName name, XmlSchemaType type ) : bool

Walks up the type inheritance structure to determine if the indicated XmlSchemaType is derived from the named type.

Method Details

GetAttributesByName() public method

Creates a (possibly empty) XmlNodeList containing all the attribute nodes identified by the given name string.
public GetAttributesByName ( string name ) : XmlNodeList
name string The name of the required elements.
return System.Xml.XmlNodeList

GetElementById() public method

Returns the XmlElement in the indexed document that has an id attribute with the given value.
public GetElementById ( string id ) : XmlElement
id string The required id attribute value.
return System.Xml.XmlElement

GetElementsByName() public method

Creates a (possibly empty) XmlNodeList containing all the element nodes identified by the given name string.
public GetElementsByName ( string name ) : XmlNodeList
name string The name of the required elements.
return System.Xml.XmlNodeList

GetElementsByType() public method

Creates a (possibly empty) XmlNodeList containing all the element nodes of a given type (or a derived subtype).
public GetElementsByType ( string ns, string type ) : XmlNodeList
ns string The required namespace URI.
type string The required type.
return System.Xml.XmlNodeList

NodeIndex() public method

Constructs a NodeIndex for the given XmlDocument.
public NodeIndex ( XmlDocument document ) : System
document System.Xml.XmlDocument The to be indexed.
return System