XmlConvert.VerifyName Method
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Verifies that the name is a valid name according to the W3C Extended Markup Language recommendation.
Assembly: System.Xml (in System.Xml.dll)
Parameters
- name
- Type: System.String
The name to verify.
| Exception | Condition |
|---|---|
| XmlException | name is not a valid XML name. |
| ArgumentNullException | name is null or String.Empty. |
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
}
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();
}
Show: