I've not used XML too much and I need a little help.
My .NET application gets this XML response from the W3C's public validation server:
<?xml version="1.0" encoding="UTF-8" ?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
<env:Body>
<m:markupvalidationresponse env:encodingStyle="http://www.w3.org/2003/05/soap-encoding" xmlns:m="http://www.w3.org/2005/10/markup-validator">
<m:uri>upload://Form Submission</m:uri>
<m:checkedby>http://validator.w3.org/</m:checkedby>
<m:doctype>-//W3C//DTD XHTML 1.1//EN</m:doctype>
<m:charset>utf-8</m:charset>
<m:validity>true</m:validity>
<m:errors>
<m:errorcount>0</m:errorcount>
<m:errorlist />
</m:errors>
<m:warnings>
<m:warningcount>0</m:warningcount>
<m:warninglist />
</m:warnings>
</m:markupvalidationresponse>
</env:Body>
</env:Envelope>
I want to extract from this the following values:
- Uri as String
- Checkedby as String
- Doctype as String
- CharSet as String
- Validity as Boolean
- ErrorList as System.Collections.Generic.List(Of W3CError)
- WarningList as System.Collections.Generic.List(Of W3CError)
That type W3CError is a small class I created with the following properties:
- Line as Integer
- Col as Integer
- Message as String
- MessageId as String
- Explanation as String
- Source as String
Here's what I've go so far. But, this doesn't work...
Dim ResponseReader As Xml.XmlTextReader = New Xml.XmlTextReader(ResponseStream) Dim ResponseDocument As New Xml.XPath.XPathDocument(ResponseReader) Dim ResponseNavigator As Xml.XPath.XPathNavigator = ResponseDocument.CreateNavigator() Dim ResponseIterator As Xml.XPath.XPathNodeIterator 'uri ResponseIterator = ResponseNavigator.Select("uri") ResponseIterator.MoveNext() _Uri = ResponseIterator.Current.Value 'checked by ResponseIterator = ResponseNavigator.Select("checkedby") ResponseIterator.MoveNext() _Checkedby = ResponseIterator.Current.Value ...etc...
How can I fix the broken code above? Or: Am I way off track with this? What's a better way?