Tree Nodes (XML))
[//]: # (title: Tree Nodes (XML)))
Represents a processing instruction. The
End properties give access to the tokens that represent the start and end of the processing instruction, namely the
?> tokens respectively. The
InstructionTargetNode property is an
IXmlIdentifier that represents the target of the processing instruction, that is, the identifier immediately following the start token. As a convenience, you can get at the text of the target using the
InstructionTarget property, which simply calls
GetText() on the
IXmlIdentifier. Finally, the
Body property is a token that contains the content of the processing instruction, if any. This is a simple
XmlToken containing the text after the target, unparsed. If the instruction contains text that looks like attributes, they are not parsed - the
Body property will contain the full text.
<?xml ... ?> declaration at the start of an XML document shares similar syntax to processing instructions, it is not a processing instruction, and is instead represented using the
Marker interface for a token representing the asterisk character (
Represents an attribute. The
Identifier property returns the tree node that contains the name of the attribute, and the
AttributeName convenience property will retrieve the full text of the attribute name, including namespace prefix, if applicable.
XmlNamespace properties will retrieve the text of the attribute name split into local name and namespace prefix, respectively. E.g.
foo:bar="quux" will return
XmlNamespace. If there is no namespace prefix, an empty string is returned (the
XmlNamespace property is annotated with
XmlNamespaceRange properties return the ranges of the
XmlNamespace strings relative to the
Identifier node. That is, they are the offsets into
Value property will return the
IXmlAttributeValue node representing the value, while the
UnquotedValue property will return the string value of the attribute, without surround quotes.
Eq property is the token representing the equals sign in the attribute declaration, e.g.
Represents a node that can contain attributes. This is typically mostly inherited by
IXmlTagHeader, but also by
IXmlProcessingInstruction in order to expose the attributes defined in the XML declaration. The
Attributes collection is pre-iterated and backed by an array, while the
AttributesEnumerable is lazily evaluated.
ContainerName property returns the text of the child
IXmlIdentifier node of the container. In other words, for an XML tag, it will return the name of the tag. For an XML declaration, it will return the "xml" part of the
<?xml ... ?> declaration.
Represents the value in an attribute. It is implemented by the
XmlValueToken type, and represents the quoted part of the value in an XML attribute
ValueToken property provides access to an instance of
IXmlValueToken token that essentially represents the same information (indeed, the
XmlValueToken implementation simply returns
An XML CDATA node. The
Start property is the
<![CDATA[ token, and
End is the
]]> token. While they are listed as
IXmlToken instances, they are in fact, instances of the
IXmlCdataEndTokenNode marker interfaces.
Body is a token representing the content of the CDATA node, while the
CData property is the content as a plain string.
Marker interface for the CDATA end token
Marker interface for the CDATA start token
Marker interface for a token representing the comma character (
Represents an XML comment. See
Marker interface for the XML comment close token
Represents and XML comment. The
CommentEnd properties are the start (
<!--) and end (
-->) tokens of the comment. Although listed here as
IXmlToken, they are in fact instances of the
IXmlCommentEndTokenNode marker interfaces. The comment text is held in the
CommentBody node, and exposed as a string with the
Marker interface for the XML comment start token
See also: IXmlTreeNode
Marker interface representing the document node of an XML file. Inherited by
Marker interface for the start token (
<!DOCTYPE) of an inline DTD declaration.
An XML entity reference token representing content such as
IsNumericEntity property is true if the entity begins with the string
Name property is the name of the entity, with the ampersand and semi-colon removed, or
null for numeric entities. That is,
© will return
• will return
Marker interface for a token representing the equals character (
Exposes a collection of processing instructions and the collection of element types used by this flavour of XML. See the overview for more information about the element types.
Marker interface for a non-fixed length token, e.g. identifiers, text, entity references or whitespace. Note that the default implementation (
XmlFloatingTextToken) is used for text, while the derived
XmlIdentifier are used for the other node types. This is so that they can implement other interfaces, such as
IXmlIdentifier. Or in the case of
XmlWhitespaceToken, to override
ITreeNode.IsFiltered() to return
An XML identifier, with optional namespace prefix. The
XmlName property returns the text of the identifier without the namespace prefix, while the
XmlNamespace property returns the prefix, if any. E.g.
"foo:bar" will return
XmlNamespace. If there is no namespace prefix,
XmlNamespace returns an empty string (the property is marked with the
[NotNull] annotation attribute).
XmlNamespaceRange properties return the ranges of the namespace and local name, relative to the start of the identifier node. If there is no namespace prefix, the range returned by
XmlNamespaceRange is empty.
Marker interface for a token representing the left bracket character (
Marker interface for a token representing the left parenthesis character (
Marker interface for a token representing the "or" or "pipe" character (
Marker interface for a token representing the percent character (
Marker interface for the processing instruction end token
Marker interface for the processing instruction start token
Marker interface for a token representing the plus character (
Represents the XML declaration at the start of an XML file, usually of the form:
Access to the attributes is available via the derived
IXmlAttributeContainer interface members.
Marker interface for a token representing the question mark character (
Marker interface for a token representing the right bracket character (
Marker interface for a token representing the right parenthesis character (
Represents a syntax error in the tree. Does not derive from
ErrorDescription property provides textual representation of the error, which can be displayed to the user, e.g. as a tooltip. The
ErrorType property is an instance of
XmlSyntaxErrorType, which can be compared against the static field instances available on the
Represents a complete XML element. The
Footer properties represent the opening and closing tags of the element. Attributes can be retrieved via the
Header property (see
The inner content can be retrieved in several ways:
InnerXmlprovides a tree range (relative to the tree) of all nodes after the header, and before the footer, including whitespace. This span will encompass all immediate child nodes (and therefore all descendant nodes, too).
InnerTextwill return the text from the range returned by
InnerXml. The text will therefore include all child and descendant tags and content.
InnerTextTokenswill return all token nodes (see
IXmlToken) that are deemed to be "text" tokens. It does this by calling
IXmlToken.GetTokenType()and looking that type up in the
tag.XmlTokenTypes.TEXT_NODESset. This set is initialised to
XmlTokenTypes.CHAR_REF. This means, it will include all instances of
InnerValuereturns a string containing the content of the child text nodes, including text, entity references, whitespace and CDATA nodes. This property will also check to see if whitespace should be preserved, by using the
XmlLangaugeSupport.IsSpacePreservedmethod to look for
xml:space="preserved"on parent tags.
IsEmptyTag property will return true if
Header.IsClosed returns true. That is, if the tag is of the form
RemoveAttribute methods will add or remove attributes from the tag header. Passing
null as the anchor parameter will insert the attribute before the first attribute for
AddAttributeAfter and after the last attribute for
AddAttributeBefore. The attribute must have been created beforehand, using the
XmlElementFactory class. If the tag is part of a physical tree (that is, associated with a file, and not created as part of a sandbox), then the implementations must take the write lock before adding or removing attributes. The modifications can be performed using
Child tags can be retrieved and modified using the
IXmlTagContainer derived interface.
See also: IXmlTag
This interface provides several means of retrieving child tags. Unless otherwise stated, all tags are immediate children of the current tag. When a method is declared as generic, it will filter the child tags so that they match the type passed in. This type must implement
IXmlTag, and is mostly useful for finding a specific tag when working with XML-derived languages, such as web.config files or build scripts.
InnerTagsproperty provides a (pre-iterated) collection of child
GetTag(Predicate<IXmlTag> predicate)will return the first child tag that matches the given predicate.
GetTags<T>()will return a lazily-evaluated enumerable of child tags, filtered to instances of the generic type
Tpassed to the method.
GetTags2<T>()will return a pre-iterated collection of child tags. It is similar to
InnerTags, except it will filter all instances to the type passed in as
GetNestedTags<T>(string xpath)will return a list of
IXmlTaginstances that match a very simple XPath-like expression. The expression only supports
"/", and must start with a tag name. The implementation (
XPathUtil.GetNestedTags<T>()) will split the path on the
"/"char, and match each path segment. If the path segment is
"*"it will match any tag at that level. It does not provide support for matching attributes or skipping path segments with
"//". Again, the found tags must also match the type of
Tpassed to the method.
RemoveTag methods provide means of adding and removing already created tags to the tag container. Implementations will ensure that tag container is not a self-closed tag (using
XmlTagUtil.MakeCompound) and will then use methods in
XmlContainerUtil to add or remove the tags. Implementations will also ensure that the write lock is taken, if the tag container is part of a physical tree (that is, associated with a file, and not a sandbox). Tags can be created using the
XmlElementFactory derived classes.
Marker interface for a self-closing XML tag end token
Marker interface for an XML tag end token
Represents the closing tag of an XML element. Not present if the XML tag is self-closing/empty. The
StartNode is an instance of
IXmlTagStart1TokenNode representing the
EndNode is the closing
Name property is the identifier representing the name of the element being closed.
Represents the opening tag of an XML element. I.e. given the following XML:
<foo baz="quux"> will be an instance of
EndNode properties represent the
> characters, and will be instances of the
IXmlTagEndTokenNode marker interfaces.
<bar baz="quux" /> will also be an instance of
IXmlTagHeader, but will return an instance of
IXmlTagEnd1TokenNode to represent the closing
/>. It will also return
true to the
Name property retrieves the
IXmlIdentifier token that represents the name of the tag. The text for the name can then be retrieved using
Attributes are accessible via the inherited
Marker interface for the start token of a closing XML tag (
Marker interface for the start token of an opening XML tag (
See also: IXmlTreeNode
Represents a token in the XML PSI tree. A token is a leaf node in the tree, and cannot be split into smaller nodes. It is the smallest building block node used when creating the tree. For example:
When parsed, this is split into the following tokens:
/>. These tokens are then used to build higher level constructs in the PSI tree - a tag, with a start token, identifier, attributes (which themselves are composed of tokens) and a close tag token.
GetTokenType method returns the
XmlTokenNodeType of the particular token. It will be equal to one of the properties set on
XmlTokenTypes. Note that this method overrides and hides the
ITokenNode.GetTokenType method, however, the returned
XmlTokenNodeType derives from
TokenNodeType and also implements
ITokenNodeType. One useful method for the returned token type is to check if the node is a whitespace node -
Root interface for all XML tree nodes, from tokens to other non-leaf nodes. The
XmlTokenTypes property retrieves the instance of
XmlTokenTypes used to construct the tree. This might be a derived instance in the cases that the XML dialect defines new constructs (e.g. XAML).
AcceptVisitor method implements the Visitor pattern. It will call the strongly typed
Visit method of the
IXmlTreeVisitor instance passed in.
Represents a token that is a quoted value. Mostly used to represent the value in an attribute. The
UnquotedValue property provides the content of the token without the surrounding quotes, while the
UnquotedValueRange property provides the offsets to the unquoted value, relative to the start of the node.