[Serializable] |
The simple XML object model for an element consists of the following parts:
<tag>
and
</tag>
. It is strongly suggested that attribute based XML representation is used to express security elements and their values. This means properties of an element are expressed as attributes and property values are expressed as attribute values. Avoid nesting text within tags. For any
<tag>text</tag>
representation a representation of type
<tag value="text"/>
is usually available. Using this attribute-based XML representation increases readability and allows easy WMI portability of the resulting XML serialization.
An attribute name must be one character or longer, and cannot be null. If element-based value representation is used, elements with a text string that is null are represented in the
<tag/>
form; otherwise, text is delimited by the
<tag>
and
</tag>
tokens. Both forms can be combined with attributes, which are shown if present.
The tags, attributes, and text of elements, if present, are always case-sensitive. The XML form contains quotations and escapes where necessary. String values that include characters invalid for use in XML result in an ArgumentException. These rules apply to all properties and methods.
ctor #1 | Overloaded:.ctor(string tag) Initializes a new instance of the SecurityElement class with the specified tag. |
ctor #2 | Overloaded:.ctor(string tag, string text) Initializes a new instance of the SecurityElement class with the specified tag and text. |
Attributes | Read-write Gets or sets the attributes of an XML element as name/value pairs. |
Children | Read-write Gets or sets the array of child elements of the XML element. |
Tag | Read-write Gets or sets the tag name of an XML element. |
Text | Read-write Gets or sets the text within an XML element. |
AddAttribute | Adds a name/value attribute to an XML element. |
AddChild | Adds a child element to the XML element. |
Attribute | Finds an attribute by name in an XML element. |
Equal | Compares two XML element objects for equality. |
Equals (inherited from System.Object) |
See base class member description: System.Object.Equals Derived from System.Object, the primary base class for all objects. |
Escape | Replaces invalid XML characters in a string with their valid XML equivalent. |
GetHashCode (inherited from System.Object) |
See base class member description: System.Object.GetHashCode Derived from System.Object, the primary base class for all objects. |
GetType (inherited from System.Object) |
See base class member description: System.Object.GetType Derived from System.Object, the primary base class for all objects. |
IsValidAttributeName | Determines whether a string is a valid attribute name. |
IsValidAttributeValue | Determines whether a string is a valid attribute value. |
IsValidTag | Determines whether a string is a valid tag. |
IsValidText | Determines whether a string is valid as text within an XML element. |
SearchForChildByTag | Finds a child by its tag name. |
SearchForTextOfTag | Finds a child by its tag name and returns the contained text. |
ToString | Overridden: Produces a string representation of an XML element and its constituent attributes, child elements, and text. |
Finalize (inherited from System.Object) |
See base class member description: System.Object.Finalize Derived from System.Object, the primary base class for all objects. |
MemberwiseClone (inherited from System.Object) |
See base class member description: System.Object.MemberwiseClone Derived from System.Object, the primary base class for all objects. |
Hierarchy:
public SecurityElement( |
tag
Exception Type | Condition |
---|---|
ArgumentNullException | The tag parameter is null. |
ArgumentException | The tag parameter is invalid in XML. |
tag
text
Exception Type | Condition |
---|---|
ArgumentNullException | The tag parameter is null. |
ArgumentException | The tag parameter or text parameter is invalid in XML. |
public Hashtable Attributes {get; set;}
|
Exception Type | Condition |
---|---|
ArgumentException | The name or value of the Hashtable object is invalid. |
Names and values in attributes should contain only valid XML attribute characters. Use SecurityElement.Escape to remove invalid characters from the string.
There is no support for quoted strings, so strings for name/value pairs should not contain quotes or other characters requiring quoting.
public ArrayList Children {get; set;}
|
Exception Type | Condition |
---|---|
ArgumentNullException | A child of the XML parent node is null. |
public string Tag {get; set;}
|
Exception Type | Condition |
---|---|
ArgumentNullException | The tag is null. |
ArgumentException | The tag is not valid in XML. |
<tag attributes>text</tag>
If this element has child elements, the children will replace
text
.
Assign only valid XML tag strings to this property. Use SecurityElement.Escape to remove invalid characters from the string.
public string Text {get; set;}
|
Exception Type | Condition |
---|---|
ArgumentException | The text is not valid in XML. |
If a SecurityElement contains both SecurityElement.Text and SecurityElement.Children, SecurityElement.Text will appear first.
name
value
Exception Type | Condition |
---|---|
ArgumentNullException | The name parameter or value parameter is null. |
ArgumentException | The name parameter or value parameter is invalid in XML. -or- An attribute with the name specified by the name parameter already exists. |
There is no support for quoted strings, so strings for name/value pairs should not contain quotes or other characters requiring quoting.
public void AddChild( |
child
Exception Type | Condition |
---|---|
ArgumentNullException | The child parameter is null. |
name
Exception Type | Condition |
---|---|
ArgumentNullException | The name parameter is null. |
Attribute("B")
would return "456".
<thetag A="123" B="456" C="789">text</thetag>
public bool Equal( |
other
There is no support for comparing different XML representations of the same characters.
str
The following table shows the invalid XML characters and their escaped equivalents.
invalid XML Character | Replaced With |
---|---|
"<" | "<" |
">" | ">" |
"\"" | """ |
"\'" | "'" |
"&" | "&" |
~SecurityElement(); |
public virtual int GetHashCode(); |
public Type GetType(); |
name
value
tag
text
protected object MemberwiseClone(); |
public SecurityElement SearchForChildByTag( |
tag
Exception Type | Condition |
---|---|
ArgumentNullException | The tag parameter is null. |
SearchForChildByTag("second")
would return the child element
<second>
.
<thetag A="123" B="456" C="789"> <first>text1</first>
<second>text2</second></thetag>
tag
Exception Type | Condition |
---|---|
ArgumentNullException | tag is null. |
String SearchForTextOfTag(String tag) { SecurityElement element = this.SearchForChildByTag(tag); return element.Text; }
SearchForTextOfTag("second")
would return "text2".
<thetag A="123" B="456" C="789"> <first>text1</first>
<second>text2</second></thetag>
public override string ToString(); |