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¶
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¶
Properties¶
Attributes¶
public List<XmlProperty> Attributes { get; }
Property Value¶
Children¶
public List<XmlNode> Children { get; }
Property Value¶
Line¶
public int Line { get; set; }
Property Value¶
LocalName¶
The name without its prefix.
public string LocalName { get; }
Property Value¶
Name¶
The name as written, with its prefix.
public string Name { get; }
Property Value¶
Origin¶
The file the element was read from (what
public string? Origin { get; set; }
Property Value¶
Text¶
The text directly inside the element, trimmed (the pieces between children are joined with a space).
public string Text { get; set; }
Property Value¶
Methods¶
Attribute(string)¶
The value of the attribute, or null.
public string? Attribute(string name)
Parameters¶
name string
Returns¶
Child(string)¶
The first child with this name (or local name), or null.
public XmlNode? Child(string name)
Parameters¶
name string
Returns¶
Clone()¶
A copy of the element and all that is in it.
public XmlNode Clone()
Returns¶
HasAttribute(string)¶
public bool HasAttribute(string name)
Parameters¶
name string
Returns¶
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¶
Exceptions¶
The text is not well-formed XML.
RemoveAttribute(string)¶
public bool RemoveAttribute(string name)
Parameters¶
name string
Returns¶
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()