Skip to content

Class XmlNode

Namespace: Apogee.Content.Xml
Assembly: Apogee.Content.dll

An element as content files and schemas are read: its name, its attributes in the order they were written, its children, its text, and the line it starts on. Comments and processing instructions are dropped, a DTD is refused (nothing is loaded from outside the file), and names keep their prefix (xs:element, xsi:type): content is not namespace-aware, so a prefix only has to be declared.

public sealed class XmlNode

Inheritance

object ← XmlNode

Inherited Members

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()

Constructors

XmlNode(string, int)

public XmlNode(string name, int line = 0)

Parameters

name string

line int

Fields

MaxDepth

How deep elements may nest: far more than content needs, and little enough that the recursive code that walks a tree cannot run out of stack.

public const int MaxDepth = 128

Field Value

int

Properties

Attributes

public List<XmlProperty> Attributes { get; }

Property Value

List<XmlProperty>

Children

public List<XmlNode> Children { get; }

Property Value

List<XmlNode>

Line

public int Line { get; set; }

Property Value

int

LocalName

The name without its prefix.

public string LocalName { get; }

Property Value

string

Name

The name as written, with its prefix.

public string Name { get; }

Property Value

string

Origin

The file the element was read from (what was given), or null for one made in code. Kept through , so a problem in a merged definition can name the file it came from.

public string? Origin { get; set; }

Property Value

string?

Text

The text directly inside the element, trimmed (the pieces between children are joined with a space).

public string Text { get; set; }

Property Value

string

Methods

Attribute(string)

The value of the attribute, or null.

public string? Attribute(string name)

Parameters

name string

Returns

string?

Child(string)

The first child with this name (or local name), or null.

public XmlNode? Child(string name)

Parameters

name string

Returns

XmlNode?

Clone()

A copy of the element and all that is in it.

public XmlNode Clone()

Returns

XmlNode

HasAttribute(string)

public bool HasAttribute(string name)

Parameters

name string

Returns

bool

Parse(string, string)

Reads the document in text; origin names it in errors (a path).

public static XmlNode Parse(string text, string origin = "xml")

Parameters

text string

origin string

Returns

XmlNode

Exceptions

XmlParseException

The text is not well-formed XML.

RemoveAttribute(string)

public bool RemoveAttribute(string name)

Parameters

name string

Returns

bool

SetAttribute(string, string)

Sets the attribute, keeping its place if it is there.

public void SetAttribute(string name, string value)

Parameters

name string

value string

ToXml()

The element as text: two spaces of indent, \n line ends, attributes in their order, empty elements as <a/>.

public string ToXml()

Returns

string