XmlHelper
Provides helper extension methods for working with XML elements, attributes, and XML strings.
メソッド
public static bool Compare(XmlNode first, XmlNode second)
result = XmlHelper.Compare(first, second)
Compares two XmlNode objects based on their OuterXml representation.
- first
- The first XmlNode to compare.
- second
- The second XmlNode to compare.
戻り値: True if both XmlNodes have identical OuterXml representations; otherwise, false.
public static T GetAttributeValue<T>(XElement elem, XName name, T defaultValue)
result = XmlHelper.GetAttributeValue(elem, name, defaultValue)
Retrieves the value of the attribute with the specified name and converts it to the specified type.
- elem
- The XML element containing the attribute.
- name
- The name of the attribute.
- defaultValue
- The default value to return if the attribute is not found.
戻り値: The converted value of the attribute, or the default value if the attribute does not exist.
public static T GetElementValue<T>(XElement parent, XName name, T defaultValue)
result = XmlHelper.GetElementValue(parent, name, defaultValue)
Retrieves the value of the child element with the specified name and converts it to the specified type.
- parent
- The parent XML element.
- name
- The name of the child element.
- defaultValue
- The default value to return if the element is not found.
戻り値: The converted value of the child element, or the default value if the element does not exist.
public static bool IsXmlChar(char c)
result = XmlHelper.IsXmlChar(c)
Determines whether the specified character is a valid XML character.
- c
- The character to check.
戻り値: True if the character is a valid XML character; otherwise, false.
public static bool IsXmlString(string value)
result = XmlHelper.IsXmlString(value)
Determines whether the specified string contains only valid XML characters.
- value
- The string to check.
戻り値: True if all characters in the string are valid XML characters; otherwise, false.
public static XmlWriter WriteAttribute(XmlWriter writer, string name, object value)
result = XmlHelper.WriteAttribute(writer, name, value)
Writes an attribute with the specified name and value to the XmlWriter.
- writer
- The XML writer.
- name
- The name of the attribute to write.
- value
- The value of the attribute. If null, an empty string is written.
戻り値: The same instance of the XmlWriter to allow for method chaining.