Class XmlUtils
The XmlUtils class provides Shared/Static methods for manipulating xml files.
Inheritance
Namespace: DotNetNuke.Common.Utilities
Assembly: DotNetNuke.dll
Syntax
public class XmlUtils : object
Methods
| Improve this Doc View SourceAppendElement(ref XmlDocument, XmlNode, String, String, Boolean, Boolean)
The XmlUtils class provides Shared/Static methods for manipulating xml files.
Declaration
public static void AppendElement(ref XmlDocument objDoc, XmlNode objNode, string attName, string attValue, bool includeIfEmpty, bool cdata)
Parameters
| Type | Name | Description |
|---|---|---|
| XmlDocument | objDoc | |
| XmlNode | objNode | |
| System.String | attName | |
| System.String | attValue | |
| System.Boolean | includeIfEmpty | |
| System.Boolean | cdata |
AppendElement(ref XmlDocument, XmlNode, String, String, Boolean)
The XmlUtils class provides Shared/Static methods for manipulating xml files.
Declaration
public static void AppendElement(ref XmlDocument objDoc, XmlNode objNode, string attName, string attValue, bool includeIfEmpty)
Parameters
| Type | Name | Description |
|---|---|---|
| XmlDocument | objDoc | |
| XmlNode | objNode | |
| System.String | attName | |
| System.String | attValue | |
| System.Boolean | includeIfEmpty |
CreateAttribute(XmlDocument, String, String)
The XmlUtils class provides Shared/Static methods for manipulating xml files.
Declaration
public static XmlAttribute CreateAttribute(XmlDocument objDoc, string attName, string attValue)
Parameters
| Type | Name | Description |
|---|---|---|
| XmlDocument | objDoc | |
| System.String | attName | |
| System.String | attValue |
Returns
| Type | Description |
|---|---|
| XmlAttribute |
CreateAttribute(XmlDocument, XmlNode, String, String)
The XmlUtils class provides Shared/Static methods for manipulating xml files.
Declaration
public static void CreateAttribute(XmlDocument objDoc, XmlNode objNode, string attName, string attValue)
Parameters
| Type | Name | Description |
|---|---|---|
| XmlDocument | objDoc | |
| XmlNode | objNode | |
| System.String | attName | |
| System.String | attValue |
CreateCDataElement(XmlDocument, String, String)
The XmlUtils class provides Shared/Static methods for manipulating xml files.
Declaration
public static XmlElement CreateCDataElement(XmlDocument document, string nodeName, string nodeValue)
Parameters
| Type | Name | Description |
|---|---|---|
| XmlDocument | document | |
| System.String | nodeName | |
| System.String | nodeValue |
Returns
| Type | Description |
|---|---|
| XmlElement |
CreateElement(XmlDocument, String, String)
The XmlUtils class provides Shared/Static methods for manipulating xml files.
Declaration
public static XmlElement CreateElement(XmlDocument document, string nodeName, string nodeValue)
Parameters
| Type | Name | Description |
|---|---|---|
| XmlDocument | document | |
| System.String | nodeName | |
| System.String | nodeValue |
Returns
| Type | Description |
|---|---|
| XmlElement |
Deserialize(Stream, Type)
The XmlUtils class provides Shared/Static methods for manipulating xml files.
Declaration
public static object Deserialize(Stream objStream, Type type)
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | objStream | |
| Type | type |
Returns
| Type | Description |
|---|---|
| System.Object |
DeSerializeDictionary<TValue>(Stream, String)
The XmlUtils class provides Shared/Static methods for manipulating xml files.
Declaration
public static Dictionary<int, TValue> DeSerializeDictionary<TValue>(Stream objStream, string rootname)
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | objStream | |
| System.String | rootname |
Returns
| Type | Description |
|---|---|
| Dictionary<System.Int32, TValue> |
Type Parameters
| Name | Description |
|---|---|
| TValue |
DeSerializeHashtable(String, String)
The XmlUtils class provides Shared/Static methods for manipulating xml files.
Declaration
public static Hashtable DeSerializeHashtable(string xmlSource, string rootname)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | xmlSource | |
| System.String | rootname |
Returns
| Type | Description |
|---|---|
| Hashtable |
GetAttributeValue(XPathNavigator, String)
Gets the value of an attribute.
Declaration
public static string GetAttributeValue(XPathNavigator nav, string attributeName)
Parameters
| Type | Name | Description |
|---|---|---|
| XPathNavigator | nav | Parent XPathNavigator. |
| System.String | attributeName | The name of the Attribute. |
Returns
| Type | Description |
|---|---|
| System.String | The attribute value. |
GetAttributeValueAsBoolean(XPathNavigator, String, Boolean)
The XmlUtils class provides Shared/Static methods for manipulating xml files.
Declaration
public static bool GetAttributeValueAsBoolean(XPathNavigator navigator, string attributeName, bool defaultValue)
Parameters
| Type | Name | Description |
|---|---|---|
| XPathNavigator | navigator | |
| System.String | attributeName | |
| System.Boolean | defaultValue |
Returns
| Type | Description |
|---|---|
| System.Boolean |
GetAttributeValueAsInteger(XPathNavigator, String, Int32)
The XmlUtils class provides Shared/Static methods for manipulating xml files.
Declaration
public static int GetAttributeValueAsInteger(XPathNavigator navigator, string attributeName, int defaultValue)
Parameters
| Type | Name | Description |
|---|---|---|
| XPathNavigator | navigator | |
| System.String | attributeName | |
| System.Int32 | defaultValue |
Returns
| Type | Description |
|---|---|
| System.Int32 |
GetAttributeValueAsLong(XPathNavigator, String, Int64)
The XmlUtils class provides Shared/Static methods for manipulating xml files.
Declaration
public static long GetAttributeValueAsLong(XPathNavigator navigator, string attributeName, long defaultValue)
Parameters
| Type | Name | Description |
|---|---|---|
| XPathNavigator | navigator | |
| System.String | attributeName | |
| System.Int64 | defaultValue |
Returns
| Type | Description |
|---|---|
| System.Int64 |
GetNodeValue(XmlNode, String, String)
Gets the value of node.
Declaration
public static string GetNodeValue(XmlNode objNode, string nodeName, string defaultValue)
Parameters
| Type | Name | Description |
|---|---|---|
| XmlNode | objNode | Parent node. |
| System.String | nodeName | Child node to look for. |
| System.String | defaultValue | Default value to return. |
Returns
| Type | Description |
|---|---|
| System.String | The node value or |
Remarks
If the node does not exist or it causes any error the default value will be returned.
GetNodeValue(XmlNode, String)
Gets the value of node.
Declaration
public static string GetNodeValue(XmlNode objNode, string nodeName)
Parameters
| Type | Name | Description |
|---|---|---|
| XmlNode | objNode | Parent node. |
| System.String | nodeName | Child node to look for. |
Returns
| Type | Description |
|---|---|
| System.String | The node value or |
Remarks
If the node does not exist or it causes any error the default value will be returned.
GetNodeValue(XPathNavigator, String, String)
Gets the value of a child node as a
Declaration
public static string GetNodeValue(XPathNavigator navigator, string path, string defaultValue)
Parameters
| Type | Name | Description |
|---|---|---|
| XPathNavigator | navigator | A navigator pointing to the parent node. |
| System.String | path | An XPath expression to find the child node. |
| System.String | defaultValue | Default value to return if the node doesn't exist or doesn't have a value. |
Returns
| Type | Description |
|---|---|
| System.String | The value of the node or |
GetNodeValue(XPathNavigator, String)
Gets the value of a child node as a
Declaration
public static string GetNodeValue(XPathNavigator navigator, string path)
Parameters
| Type | Name | Description |
|---|---|---|
| XPathNavigator | navigator | A navigator pointing to the parent node. |
| System.String | path | An XPath expression to find the child node. |
Returns
| Type | Description |
|---|---|
| System.String | The value of the node or |
GetNodeValueBoolean(XmlNode, String, Boolean)
Gets the value of node.
Declaration
public static bool GetNodeValueBoolean(XmlNode objNode, string nodeName, bool defaultValue)
Parameters
| Type | Name | Description |
|---|---|---|
| XmlNode | objNode | Parent node. |
| System.String | nodeName | Child node to look for. |
| System.Boolean | defaultValue | Default value to return. |
Returns
| Type | Description |
|---|---|
| System.Boolean | The node value parsed as a |
Remarks
If the node does not exist or it causes any error the default value will be returned.
GetNodeValueBoolean(XmlNode, String)
Gets the value of node.
Declaration
public static bool GetNodeValueBoolean(XmlNode objNode, string nodeName)
Parameters
| Type | Name | Description |
|---|---|---|
| XmlNode | objNode | Parent node. |
| System.String | nodeName | Child node to look for. |
Returns
| Type | Description |
|---|---|
| System.Boolean | The node value parsed as a |
Remarks
If the node does not exist or it causes any error the default value (False) will be returned.
GetNodeValueBoolean(XPathNavigator, String, Boolean)
Gets the value of a child node as a
Declaration
public static bool GetNodeValueBoolean(XPathNavigator navigator, string path, bool defaultValue)
Parameters
| Type | Name | Description |
|---|---|---|
| XPathNavigator | navigator | A navigator pointing to the parent node. |
| System.String | path | An XPath expression to find the child node. |
| System.Boolean | defaultValue | Default value to return if the node doesn't exist or doesn't have a value. |
Returns
| Type | Description |
|---|---|
| System.Boolean | The value of the node or |
GetNodeValueBoolean(XPathNavigator, String)
Gets the value of a child node as a
Declaration
public static bool GetNodeValueBoolean(XPathNavigator navigator, string path)
Parameters
| Type | Name | Description |
|---|---|---|
| XPathNavigator | navigator | A navigator pointing to the parent node. |
| System.String | path | An XPath expression to find the child node. |
Returns
| Type | Description |
|---|---|
| System.Boolean | The value of the node or |
GetNodeValueDate(XmlNode, String, DateTime)
Gets the value of node.
Declaration
public static DateTime GetNodeValueDate(XmlNode objNode, string nodeName, DateTime defaultValue)
Parameters
| Type | Name | Description |
|---|---|---|
| XmlNode | objNode | Parent node. |
| System.String | nodeName | Child node to look for. |
| DateTime | defaultValue | Default value to return. |
Returns
| Type | Description |
|---|---|
| DateTime | The node value parsed as a |
Remarks
If the node does not exist or it causes any error the default value will be returned.
GetNodeValueDate(XPathNavigator, String, DateTime)
Gets the value of a child node as a
Declaration
public static DateTime GetNodeValueDate(XPathNavigator navigator, string path, DateTime defaultValue)
Parameters
| Type | Name | Description |
|---|---|---|
| XPathNavigator | navigator | A navigator pointing to the parent node. |
| System.String | path | An XPath expression to find the child node. |
| DateTime | defaultValue | Default value to return if the node doesn't exist or doesn't have a value. |
Returns
| Type | Description |
|---|---|
| DateTime | The value of the node or |
GetNodeValueInt(XmlNode, String, Int32)
Gets the value of node.
Declaration
public static int GetNodeValueInt(XmlNode node, string nodeName, int defaultValue)
Parameters
| Type | Name | Description |
|---|---|---|
| XmlNode | node | Parent node. |
| System.String | nodeName | Child node to look for. |
| System.Int32 | defaultValue | Default value to return. |
Returns
| Type | Description |
|---|---|
| System.Int32 | The node value parsed as an |
Remarks
If the node does not exist or it causes any error the default value will be returned.
GetNodeValueInt(XmlNode, String)
Gets the value of node.
Declaration
public static int GetNodeValueInt(XmlNode node, string nodeName)
Parameters
| Type | Name | Description |
|---|---|---|
| XmlNode | node | Parent node. |
| System.String | nodeName | Child node to look for. |
Returns
| Type | Description |
|---|---|
| System.Int32 | The node value parsed as an |
Remarks
If the node does not exist or it causes any error the default value (0) will be returned.
GetNodeValueInt(XPathNavigator, String, Int32)
Gets the value of a child node as an
Declaration
public static int GetNodeValueInt(XPathNavigator navigator, string path, int defaultValue)
Parameters
| Type | Name | Description |
|---|---|---|
| XPathNavigator | navigator | A navigator pointing to the parent node. |
| System.String | path | An XPath expression to find the child node. |
| System.Int32 | defaultValue | Default value to return if the node doesn't exist or doesn't have a value. |
Returns
| Type | Description |
|---|---|
| System.Int32 | The value of the node or |
GetNodeValueInt(XPathNavigator, String)
Gets the value of a child node as an
Declaration
public static int GetNodeValueInt(XPathNavigator navigator, string path)
Parameters
| Type | Name | Description |
|---|---|---|
| XPathNavigator | navigator | A navigator pointing to the parent node. |
| System.String | path | An XPath expression to find the child node. |
Returns
| Type | Description |
|---|---|
| System.Int32 | The value of the node or |
GetNodeValueSingle(XmlNode, String, Single)
Gets the value of node.
Declaration
public static float GetNodeValueSingle(XmlNode node, string nodeName, float defaultValue)
Parameters
| Type | Name | Description |
|---|---|---|
| XmlNode | node | Parent node. |
| System.String | nodeName | Child node to look for. |
| System.Single | defaultValue | Default value to return. |
Returns
| Type | Description |
|---|---|
| System.Single | The value of the node or |
Remarks
If the node does not exist or it causes any error the default value will be returned.
GetNodeValueSingle(XmlNode, String)
Gets the value of node.
Declaration
public static float GetNodeValueSingle(XmlNode node, string nodeName)
Parameters
| Type | Name | Description |
|---|---|---|
| XmlNode | node | Parent node. |
| System.String | nodeName | Child node to look for. |
Returns
| Type | Description |
|---|---|
| System.Single | The value of the node or |
Remarks
If the node does not exist or it causes any error the default value (0) will be returned.
GetNodeValueSingle(XPathNavigator, String, Single)
Gets the value of a child node as a
Declaration
public static float GetNodeValueSingle(XPathNavigator navigator, string path, float defaultValue)
Parameters
| Type | Name | Description |
|---|---|---|
| XPathNavigator | navigator | A navigator pointing to the parent node. |
| System.String | path | An XPath expression to find the child node. |
| System.Single | defaultValue | Default value to return if the node doesn't exist or doesn't have a value. |
Returns
| Type | Description |
|---|---|
| System.Single | The value of the node or |
GetNodeValueSingle(XPathNavigator, String)
Gets the value of a child node as a
Declaration
public static float GetNodeValueSingle(XPathNavigator navigator, string path)
Parameters
| Type | Name | Description |
|---|---|---|
| XPathNavigator | navigator | A navigator pointing to the parent node. |
| System.String | path | An XPath expression to find the child node. |
Returns
| Type | Description |
|---|---|
| System.Single | The value of the node or |
GetXMLContent(String)
The XmlUtils class provides Shared/Static methods for manipulating xml files.
Declaration
public static XmlDocument GetXMLContent(string contentUrl)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | contentUrl |
Returns
| Type | Description |
|---|---|
| XmlDocument |
GetXmlWriterSettings(ConformanceLevel)
Gets an XmlWriterSettings object.
Declaration
public static XmlWriterSettings GetXmlWriterSettings(ConformanceLevel conformance)
Parameters
| Type | Name | Description |
|---|---|---|
| ConformanceLevel | conformance | Conformance Level. |
Returns
| Type | Description |
|---|---|
| XmlWriterSettings | An XmlWriterSettings. |
RemoveInvalidXmlCharacters(String)
Removes control characters and other non-UTF-8 characters.
Declaration
public static string RemoveInvalidXmlCharacters(string content)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | content | The string to process. |
Returns
| Type | Description |
|---|---|
| System.String | A string with no control characters or entities above 0x00FD. |
Serialize(Object)
The XmlUtils class provides Shared/Static methods for manipulating xml files.
Declaration
public static string Serialize(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | obj |
Returns
| Type | Description |
|---|---|
| System.String |
SerializeDictionary(IDictionary, String)
The XmlUtils class provides Shared/Static methods for manipulating xml files.
Declaration
public static string SerializeDictionary(IDictionary source, string rootName)
Parameters
| Type | Name | Description |
|---|---|---|
| IDictionary | source | |
| System.String | rootName |
Returns
| Type | Description |
|---|---|
| System.String |
SerializeHashtable(Hashtable, XmlDocument, XmlNode, String, String, String)
The XmlUtils class provides Shared/Static methods for manipulating xml files.
Declaration
public static void SerializeHashtable(Hashtable hashtable, XmlDocument xmlDocument, XmlNode rootNode, string elementName, string keyField, string valueField)
Parameters
| Type | Name | Description |
|---|---|---|
| Hashtable | hashtable | |
| XmlDocument | xmlDocument | |
| XmlNode | rootNode | |
| System.String | elementName | |
| System.String | keyField | |
| System.String | valueField |
UpdateAttribute(XmlNode, String, String)
The XmlUtils class provides Shared/Static methods for manipulating xml files.
Declaration
public static void UpdateAttribute(XmlNode node, string attName, string attValue)
Parameters
| Type | Name | Description |
|---|---|---|
| XmlNode | node | |
| System.String | attName | |
| System.String | attValue |
XMLEncode(String)
XML Encodes HTML.
Declaration
public static string XMLEncode(string html)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | html | The HTML to encode. |
Returns
| Type | Description |
|---|---|
| System.String | The XML encoded HTML. |
XPathLiteral(String)
Produce an XPath literal equal to the value if possible; if not, produce an XPath expression that will match the value.
Note that this function will produce very long XPath expressions if a value contains a long run of double quotes.
Declaration
public static string XPathLiteral(string value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The value to match. |
Returns
| Type | Description |
|---|---|
| System.String | If the value contains only single or double quotes, an XPath literal equal to the value. If it contains both, an XPath expression, using concat(), that evaluates to the value. |
Remarks
From Stack Overflow (http://stackoverflow.com/a/1352556/2688).
XSLTransform(XmlDocument, ref StreamWriter, String)
The XmlUtils class provides Shared/Static methods for manipulating xml files.
Declaration
public static void XSLTransform(XmlDocument doc, ref StreamWriter writer, string xsltUrl)
Parameters
| Type | Name | Description |
|---|---|---|
| XmlDocument | doc | |
| StreamWriter | writer | |
| System.String | xsltUrl |