XmlElementConverter class | QSYS API Reference Guide
Estimated reading time: 11 minutes
Provides methods for converting between XmlElement objects and their string, boolean, and child element representations.
Namespace: ASNA.DataGate.Common
Assembly: ASNA.QSys.DataGate.Client.dll
Inheritance: Object
Constructors
Initializes a new instance of the class with the specified XML container and element name.
XmlElementConverter(XmlNode, ISchemaElementName)
Parameters
Initializes a new instance of the class with the specified XML container, XML element, and element name.
XmlElementConverter(XmlNode, XmlElement, ISchemaElementName)
Parameters
Properties
Type |
Name |
Description |
XmlDocument |
Doc |
Gets the XmlDocument that the current XmlElement belongs to. |
XmlElement |
Element |
Gets or sets the XmlElement that is being converted. |
ISchemaElementName |
ElementName |
Gets the name of the current XmlElement. |
XmlNode |
Parent |
Gets the parent XmlNode of the current XmlElement. |
String |
XsdFalse |
Represents the string “false” in XSD format. |
String |
XsdTrue |
Represents the string “true” in XSD format. |
Methods
Signature |
Description |
CreateElement(Boolean) |
Creates a new XmlElement with the specified name and appends it to the parent node. |
GetAttribute(String) |
Gets the value of the attribute with the specified name from the current XmlElement. |
GetAttribute(String, Object) |
Gets the value of the attribute with the specified name from the current XmlElement. If the attribute does not exist, returns the specified default value. |
GetChildCount(String, String) |
Gets the number of child elements of the current XmlElement with the specified name and namespace. |
GetChildren(String, String) |
Gets all child elements of the current XmlElement with the specified name and namespace. |
GetChildrenOrThrow(String, String) |
Gets all child elements of the current XmlElement with the specified name and namespace. If the current element is null, throws an InvalidOperationException. |
GetDocumentOrThrow() |
Gets the XmlDocument that the current XmlElement belongs to. If the document is null, throws an InvalidOperationException. |
GetElementOrThrow() |
Gets the XmlElement that is being converted. If the element is null, throws an InvalidOperationException. |
GetElementText() |
Gets the text of the current XmlElement. |
GetElementText(XmlElement) |
Gets the text of the specified XmlElement. |
GetFirstElement() |
Gets the first child element of the parent node that matches the specified element name and namespace. The element is stored in the Element property of this class. |
GetParentOrThrow() |
Gets the parent XmlNode of the current XmlElement. If the parent is null, throws an InvalidOperationException. |
GetXsdBool(Boolean) |
Converts a boolean value to its equivalent string representation in XSD format. |
GetXsdBooleanAttribute(String, Boolean) |
Gets the value of the attribute with the specified name from the current XmlElement and converts it to a boolean. If the attribute does not exist, returns the specified default value. |
HasAttribute(String) |
Determines whether the current XmlElement has an attribute with the specified name. |
SetAttribute(String, Object) |
Sets the value of the attribute with the specified name in the current XmlElement. |
SetElementName(ISchemaElementName) |
Sets the name of the current XmlElement to the specified value. |
SetElementText(String) |
Sets the text of the current XmlElement to the specified value. |
Creates a new XmlElement with the specified name and appends it to the parent node.
XmlElement CreateElement(bool addXmlnsAttr)
Parameters
Type |
Parameter name |
Description |
Boolean |
addXmlnsAttr |
If true, adds an xmlns attribute with the namespace of the element. |
Returns
Type |
Description |
XmlElement |
The created XmlElement. |
Gets the value of the attribute with the specified name from the current XmlElement.
string GetAttribute(string name)
Parameters
Type |
Parameter name |
Description |
String |
name |
The name of the attribute. |
Returns
Type |
Description |
String |
The value of the attribute. |
Gets the value of the attribute with the specified name from the current XmlElement. If the attribute does not exist, returns the specified default value.
string GetAttribute(string name, object defaultValue)
Parameters
Type |
Parameter name |
Description |
String |
name |
The name of the attribute. |
Object |
defaultValue |
The value to return if the attribute does not exist. |
Returns
Type |
Description |
String |
The value of the attribute, or the default value if the attribute does not exist. |
Gets the number of child elements of the current XmlElement with the specified name and namespace.
int GetChildCount(string childElementName, string childElementNamespace)
Parameters
Type |
Parameter name |
Description |
String |
childElementName |
The name of the child elements to count. |
String |
childElementNamespace |
The namespace of the child elements to count. |
Returns
Type |
Description |
Int32 |
The number of child elements with the specified name and namespace. |
Gets all child elements of the current XmlElement with the specified name and namespace.
XmlNodeList GetChildren(string childElementName, string childElementNamespace)
Parameters
Type |
Parameter name |
Description |
String |
childElementName |
The name of the child elements to get. |
String |
childElementNamespace |
The namespace of the child elements to get. |
Returns
Type |
Description |
XmlNodeList |
A collection of child elements with the specified name and namespace, or null if the current element is null. |
Gets all child elements of the current XmlElement with the specified name and namespace. If the current element is null, throws an InvalidOperationException.
Use this in cases where GetChildren() should never return null, i.e., when Element is not null.
IEnumerable<XmlElement> GetChildrenOrThrow(string childName, string childNamespace)
Parameters
Type |
Parameter name |
Description |
String |
childName |
The name of the child elements to get. |
String |
childNamespace |
The namespace of the child elements to get. |
Returns
Type |
Description |
IEnumerable`1 |
A collection of child elements with the specified name and namespace. |
XmlDocument GetDocumentOrThrow()
Gets the XmlDocument that the current XmlElement belongs to. If the document is null, throws an InvalidOperationException.
XmlDocument GetDocumentOrThrow()
XmlElement GetElementOrThrow()
Gets the XmlElement that is being converted. If the element is null, throws an InvalidOperationException.
XmlElement GetElementOrThrow()
string GetElementText()
Gets the text of the current XmlElement.
Gets the text of the specified XmlElement.
string GetElementText(XmlElement element)
Parameters
Type |
Parameter name |
Description |
XmlElement |
element |
The XmlElement to get the text from. |
Returns
Type |
Description |
String |
The text of the XmlElement, or an empty string if the element has no text. |
void GetFirstElement()
Gets the first child element of the parent node that matches the specified element name and namespace. The element is stored in the Element property of this class.
XmlNode GetParentOrThrow()
Gets the parent XmlNode of the current XmlElement. If the parent is null, throws an InvalidOperationException.
XmlNode GetParentOrThrow()
Converts a boolean value to its equivalent string representation in XSD format.
string GetXsdBool(bool value)
Parameters
Type |
Parameter name |
Description |
Boolean |
value |
The boolean value to convert. |
Returns
Type |
Description |
String |
The string representation of the boolean value in XSD format. |
Gets the value of the attribute with the specified name from the current XmlElement and converts it to a boolean. If the attribute does not exist, returns the specified default value.
bool GetXsdBooleanAttribute(string name, bool defaultValue)
Parameters
Type |
Parameter name |
Description |
String |
name |
The name of the attribute. |
Boolean |
defaultValue |
The value to return if the attribute does not exist. |
Returns
Type |
Description |
Boolean |
The boolean value of the attribute, or the default value if the attribute does not exist. |
Determines whether the current XmlElement has an attribute with the specified name.
bool HasAttribute(string name)
Parameters
Type |
Parameter name |
Description |
String |
name |
The name of the attribute. |
Returns
Type |
Description |
Boolean |
true if the current XmlElement has an attribute with the specified name; otherwise, false. |
Sets the value of the attribute with the specified name in the current XmlElement.
void SetAttribute(string name, object val)
Parameters
Type |
Parameter name |
Description |
String |
name |
The name of the attribute. |
Object |
val |
The value to set for the attribute. |
Sets the name of the current XmlElement to the specified value.
void SetElementName(ISchemaElementName name)
Parameters
Type |
Parameter name |
Description |
ISchemaElementName |
name |
The new name for the current XmlElement. |
Sets the text of the current XmlElement to the specified value.
void SetElementText(string text)
Parameters
Type |
Parameter name |
Description |
String |
text |
The value to set as the text of the current XmlElement. |