XmlConvert.VerifyName Method
Microsoft Silverlight will reach end of support after October 2021. Learn more.
Verifies that the name is a valid name according to the W3C Extended Markup Language recommendation.
Namespace: System.Xml
Assembly: System.Xml (in System.Xml.dll)
Syntax
'Declaration
Public Shared Function VerifyName ( _
name As String _
) As String
public static string VerifyName(
string name
)
Parameters
- name
Type: System.String
The name to verify.
Return Value
Type: System.String
The name, if it is a valid XML name.
Exceptions
Exception | Condition |
---|---|
XmlException | name is not a valid XML name. |
ArgumentNullException | name is nulla null reference (Nothing in Visual Basic) or String.Empty. |
Remarks
This method can be used with the XmlWriter class in the following manner.
try{
writer.WriteStartElement(XmlConvert.VerifyName("item"),"bar");
}
catch(Exception e)
{
//show error
}
Examples
Dim xmlString As String = _
"<?xml version='1.0'?>" & _
"<transactions>" & _
"<transaction>" & _
"<id>123456789</id>" & _
"<amount>1.00</amount>" & _
"<currency>USD</currency>" & _
"<time>2007-08-03T22:05:13-07:00</time>" & _
"</transaction>" & _
"</transactions>"
' Create an XmlReader
Using reader As XmlReader = XmlReader.Create(New StringReader(xmlString))
reader.ReadToFollowing("time")
Dim time As String = reader.ReadElementContentAsString()
' Read the element contents as a string and covert to DateTimeOffset type
' The format of time must be a subset of the W3C Recommendation for the XML dateTime type
Dim transaction_time As DateTimeOffset = XmlConvert.ToDateTimeOffset(time)
OutputTextBlock.Text = transaction_time.ToString()
End Using
String xmlString =
@"<?xml version='1.0'?>
<transactions>
<transaction>
<id>123456789</id>
<amount>1.00</amount>
<currency>USD</currency>
<time>2007-08-03T22:05:13-07:00</time>
</transaction>
</transactions>";
// Create an XmlReader
using (XmlReader reader = XmlReader.Create(new StringReader(xmlString)))
{
reader.ReadToFollowing("time");
string time = reader.ReadElementContentAsString();
// Read the element contents as a string and covert to DateTimeOffset type
// The format of time must be a subset of the W3C Recommendation for the XML dateTime type
DateTimeOffset transaction_time = XmlConvert.ToDateTimeOffset(time);
OutputTextBlock.Text = transaction_time.ToString();
}
Version Information
Silverlight
Supported in: 5, 4, 3
Silverlight for Windows Phone
Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0
XNA Framework
Supported in: Xbox 360, Windows Phone OS 7.0
Platforms
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.