C# Class SIL.Utils.XmlUtils

Summary description for XmlUtils.
Datei anzeigen Open project: sillsdev/FieldWorks

Public Methods

Method Description
AppendAttribute ( XmlNode parent, string attrName, string attrVal ) : void

Append an attribute with the specified name and value to parent.

AppendElement ( XmlNode parent, string elementName ) : XmlElement

Append an attribute with the specified name and value to parent.

CloneNodeWithDocument ( XmlNode node ) : XmlNode

return the deep clone of the given node, in a clone of its document context.

CreateTransform ( string xslName, string assemblyName ) : XslCompiledTransform
DecodeXml ( string sInput ) : string

Convert an encoded string (safe XML) into plain text.

DecodeXmlAttribute ( string sInput ) : string

Convert an encoded attribute string into plain text.

FindIndexOfMatchingNode ( IEnumerable nodes, XmlNode target ) : int

Find the index of the node in nodes that 'matches' the target node. Return -1 if not found.

FindNode ( XmlNode node, string name ) : XmlNode

Return the node that has the desired 'name', either the input node or a decendent.

GetAttributeValue ( XmlNode node, string attrName ) : string

Get an optional attribute value from an XmlNode.

GetAttributeValue ( XmlNode node, string attrName, string defaultValue ) : string

Deprecated: use GetOptionalAttributeValue instead.

GetBooleanAttributeValue ( XmlNode node, string attrName ) : bool

Returns true if value of attrName is 'true' or 'yes' (case ignored)

GetBooleanAttributeValue ( string sValue ) : bool

Returns true if sValue is 'true' or 'yes' (case ignored)

GetFirstNonCommentChild ( XmlNode node ) : XmlNode

Return the first child of the node that is not a comment (or null).

GetLocalizedAttributeValue ( SIL.Utils.StringTable tbl, XmlNode node, string attrName, string defaultString ) : string

Get an optional attribute value from an XmlNode, and look up its localized value in the given StringTable.

GetMandatoryIntegerAttributeValue ( XmlNode node, string attrName ) : int

Returns a integer obtained from the (mandatory) attribute named.

GetMandatoryIntegerListAttributeValue ( XmlNode node, string attrName ) : int[]

Retrieve an array, given an attribute consisting of a comma-separated list of integers

GetMandatoryUIntegerListAttributeValue ( XmlNode node, string attrName ) : uint[]

Retrieve an array, given an attribute consisting of a comma-separated list of integers

GetManditoryAttributeValue ( XmlNode node, string attrName ) : string

Get an obligatory attribute value.

GetOptionalAttributeValue ( XmlNode node, string attrName ) : string

Get an optional attribute value from an XmlNode.

GetOptionalAttributeValue ( XmlNode node, string attrName, string defaultString ) : string

Get an optional attribute value from an XmlNode.

GetOptionalBooleanAttributeValue ( XmlNode node, string attrName, bool defaultValue ) : bool

Get an optional attribute value from an XmlNode.

GetOptionalIntegerValue ( XmlNode node, string attrName, int defaultVal ) : int

Return an optional integer attribute value, or if not found, the default value.

GetStaticMethod ( XmlNode node, string sAssemblyAttr, string sClassAttr, string sMethodName, Type &typeFound ) : MethodInfo

Utility function to find a methodInfo for the named method. It is a static method of the class specified in the EditRowClass of the EditRowAssembly.

GetXPathInDocument ( XmlNode node ) : string

build an xpath to the given node in its document.

MakeIntegerListValue ( int vals ) : string

Make a value suitable for GetMandatoryIntegerListAttributeValue to parse.

MakeListValue ( List vals ) : string

Make a comma-separated list of the ToStrings of the values in the list.

MakeListValue ( List vals ) : string

Make a comma-separated list of the ToStrings of the values in the list.

MakeSafeXml ( string sInput ) : string

Fix the string to be safe in a text region of XML.

MakeSafeXmlAttribute ( string sInput ) : string

Fix the string to be safe in an attribute value of XML.

NodesMatch ( XmlNode node1, XmlNode node2 ) : bool

Return true if the two nodes match. Corresponding children should match, and corresponding attributes (though not necessarily in the same order). The nodes are expected to be actually XmlElements; not tested for other cases. Comments do not affect equality.

SerializeObjectToXmlString ( object objToSerialize ) : string

Try to serialize the given object into an xml string

SetAttribute ( XmlNode parent, string attrName, string attrVal ) : void

Change the value of the specified attribute, appending it if not already present.

VisitAttributes ( XmlNode input, IAttributeVisitor visitor ) : bool

Allow the visitor to 'visit' each attribute in the input XmlNode.

Protected Methods

Method Description
MakeGetStaticMethodErrorMessage ( string sMainMsg, string sContext ) : string

Private Methods

Method Description
ConvertMultiparagraphToSafeXml ( string sInput ) : string
DeserializeXmlString ( string xml, Type targetType ) : object
GetIndexAmongSiblings ( XmlNode node ) : int
GetStaticMethod ( string sAssemblyName, string sClassName, string sMethodName, string sContext, Type &typeFound ) : MethodInfo

Method Details

AppendAttribute() public static method

Append an attribute with the specified name and value to parent.
public static AppendAttribute ( XmlNode parent, string attrName, string attrVal ) : void
parent System.Xml.XmlNode
attrName string
attrVal string
return void

AppendElement() public static method

Append an attribute with the specified name and value to parent.
public static AppendElement ( XmlNode parent, string elementName ) : XmlElement
parent System.Xml.XmlNode
elementName string
return System.Xml.XmlElement

CloneNodeWithDocument() public static method

return the deep clone of the given node, in a clone of its document context.
public static CloneNodeWithDocument ( XmlNode node ) : XmlNode
node System.Xml.XmlNode
return System.Xml.XmlNode

CreateTransform() public static method

public static CreateTransform ( string xslName, string assemblyName ) : XslCompiledTransform
xslName string
assemblyName string
return System.Xml.Xsl.XslCompiledTransform

DecodeXml() public static method

Convert an encoded string (safe XML) into plain text.
public static DecodeXml ( string sInput ) : string
sInput string
return string

DecodeXmlAttribute() public static method

Convert an encoded attribute string into plain text.
public static DecodeXmlAttribute ( string sInput ) : string
sInput string
return string

FindIndexOfMatchingNode() public static method

Find the index of the node in nodes that 'matches' the target node. Return -1 if not found.
public static FindIndexOfMatchingNode ( IEnumerable nodes, XmlNode target ) : int
nodes IEnumerable The nodes.
target System.Xml.XmlNode The target.
return int

FindNode() public static method

Return the node that has the desired 'name', either the input node or a decendent.
public static FindNode ( XmlNode node, string name ) : XmlNode
node System.Xml.XmlNode The XmlNode to look in.
name string The XmlNode name to find.
return System.Xml.XmlNode

GetAttributeValue() public static method

Get an optional attribute value from an XmlNode.
public static GetAttributeValue ( XmlNode node, string attrName ) : string
node System.Xml.XmlNode The XmlNode to look in.
attrName string The attribute to find.
return string

GetAttributeValue() public static method

Deprecated: use GetOptionalAttributeValue instead.
public static GetAttributeValue ( XmlNode node, string attrName, string defaultValue ) : string
node System.Xml.XmlNode
attrName string
defaultValue string
return string

GetBooleanAttributeValue() public static method

Returns true if value of attrName is 'true' or 'yes' (case ignored)
public static GetBooleanAttributeValue ( XmlNode node, string attrName ) : bool
node System.Xml.XmlNode The XmlNode to look in.
attrName string The optional attribute to find.
return bool

GetBooleanAttributeValue() public static method

Returns true if sValue is 'true' or 'yes' (case ignored)
public static GetBooleanAttributeValue ( string sValue ) : bool
sValue string
return bool

GetFirstNonCommentChild() public static method

Return the first child of the node that is not a comment (or null).
public static GetFirstNonCommentChild ( XmlNode node ) : XmlNode
node System.Xml.XmlNode
return System.Xml.XmlNode

GetLocalizedAttributeValue() public static method

Get an optional attribute value from an XmlNode, and look up its localized value in the given StringTable.
public static GetLocalizedAttributeValue ( SIL.Utils.StringTable tbl, XmlNode node, string attrName, string defaultString ) : string
tbl SIL.Utils.StringTable
node System.Xml.XmlNode
attrName string
defaultString string
return string

GetMandatoryIntegerAttributeValue() public static method

Returns a integer obtained from the (mandatory) attribute named.
public static GetMandatoryIntegerAttributeValue ( XmlNode node, string attrName ) : int
node System.Xml.XmlNode The XmlNode to look in.
attrName string The mandatory attribute to find.
return int

GetMandatoryIntegerListAttributeValue() public static method

Retrieve an array, given an attribute consisting of a comma-separated list of integers
public static GetMandatoryIntegerListAttributeValue ( XmlNode node, string attrName ) : int[]
node System.Xml.XmlNode
attrName string
return int[]

GetMandatoryUIntegerListAttributeValue() public static method

Retrieve an array, given an attribute consisting of a comma-separated list of integers
public static GetMandatoryUIntegerListAttributeValue ( XmlNode node, string attrName ) : uint[]
node System.Xml.XmlNode
attrName string
return uint[]

GetManditoryAttributeValue() public static method

Get an obligatory attribute value.
/// Thrown when the value is not found in the node. ///
public static GetManditoryAttributeValue ( XmlNode node, string attrName ) : string
node System.Xml.XmlNode The XmlNode to look in.
attrName string The required attribute to find.
return string

GetOptionalAttributeValue() public static method

Get an optional attribute value from an XmlNode.
public static GetOptionalAttributeValue ( XmlNode node, string attrName ) : string
node System.Xml.XmlNode The XmlNode to look in.
attrName string The attribute to find.
return string

GetOptionalAttributeValue() public static method

Get an optional attribute value from an XmlNode.
public static GetOptionalAttributeValue ( XmlNode node, string attrName, string defaultString ) : string
node System.Xml.XmlNode The XmlNode to look in.
attrName string The attribute to find.
defaultString string
return string

GetOptionalBooleanAttributeValue() public static method

Get an optional attribute value from an XmlNode.
public static GetOptionalBooleanAttributeValue ( XmlNode node, string attrName, bool defaultValue ) : bool
node System.Xml.XmlNode The XmlNode to look in.
attrName string The attribute to find.
defaultValue bool
return bool

GetOptionalIntegerValue() public static method

Return an optional integer attribute value, or if not found, the default value.
public static GetOptionalIntegerValue ( XmlNode node, string attrName, int defaultVal ) : int
node System.Xml.XmlNode
attrName string
defaultVal int
return int

GetStaticMethod() public static method

Utility function to find a methodInfo for the named method. It is a static method of the class specified in the EditRowClass of the EditRowAssembly.
public static GetStaticMethod ( XmlNode node, string sAssemblyAttr, string sClassAttr, string sMethodName, Type &typeFound ) : MethodInfo
node System.Xml.XmlNode
sAssemblyAttr string
sClassAttr string
sMethodName string
typeFound System.Type
return System.Reflection.MethodInfo

GetXPathInDocument() public static method

build an xpath to the given node in its document.
public static GetXPathInDocument ( XmlNode node ) : string
node System.Xml.XmlNode
return string

MakeGetStaticMethodErrorMessage() static protected method

static protected MakeGetStaticMethodErrorMessage ( string sMainMsg, string sContext ) : string
sMainMsg string
sContext string
return string

MakeIntegerListValue() public static method

Make a value suitable for GetMandatoryIntegerListAttributeValue to parse.
public static MakeIntegerListValue ( int vals ) : string
vals int
return string

MakeListValue() public static method

Make a comma-separated list of the ToStrings of the values in the list.
public static MakeListValue ( List vals ) : string
vals List
return string

MakeListValue() public static method

Make a comma-separated list of the ToStrings of the values in the list.
public static MakeListValue ( List vals ) : string
vals List
return string

MakeSafeXml() public static method

Fix the string to be safe in a text region of XML.
public static MakeSafeXml ( string sInput ) : string
sInput string
return string

MakeSafeXmlAttribute() public static method

Fix the string to be safe in an attribute value of XML.
public static MakeSafeXmlAttribute ( string sInput ) : string
sInput string
return string

NodesMatch() static public method

Return true if the two nodes match. Corresponding children should match, and corresponding attributes (though not necessarily in the same order). The nodes are expected to be actually XmlElements; not tested for other cases. Comments do not affect equality.
static public NodesMatch ( XmlNode node1, XmlNode node2 ) : bool
node1 System.Xml.XmlNode
node2 System.Xml.XmlNode
return bool

SerializeObjectToXmlString() public static method

Try to serialize the given object into an xml string
public static SerializeObjectToXmlString ( object objToSerialize ) : string
objToSerialize object
return string

SetAttribute() public static method

Change the value of the specified attribute, appending it if not already present.
public static SetAttribute ( XmlNode parent, string attrName, string attrVal ) : void
parent System.Xml.XmlNode
attrName string
attrVal string
return void

VisitAttributes() public static method

Allow the visitor to 'visit' each attribute in the input XmlNode.
public static VisitAttributes ( XmlNode input, IAttributeVisitor visitor ) : bool
input System.Xml.XmlNode
visitor IAttributeVisitor
return bool