【发布时间】:2009-03-05 21:57:41
【问题描述】:
我没有过多地使用 XML,我需要一点帮助。
我的 .NET 应用程序从 W3C 的公共验证服务器获取此 XML 响应:
<?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>
我想从中提取以下值:
- Uri 作为字符串
- Checkedby 作为字符串
- 文档类型为字符串
- CharSet 为字符串
- 布尔值的有效性
- ErrorList as System.Collections.Generic.List(Of W3CError)
- WarningList as System.Collections.Generic.List(Of W3CError)
W3CError 类型是我创建的一个小类,具有以下属性:
- 行为整数
- Col 作为整数
- 字符串形式的消息
- MessageId 作为字符串
- 字符串解释
- 来源为字符串
这是我到目前为止所做的。但是,这行不通...
Dim ResponseReader As Xml.XmlTextReader = New Xml.XmlTextReader(ResponseStream) 将 ResponseDocument 变暗为新的 Xml.XPath.XPathDocument(ResponseReader) 将 ResponseNavigator 调暗为 Xml.XPath.XPathNavigator = ResponseDocument.CreateNavigator() Dim ResponseIterator As Xml.XPath.XPathNodeIterator 乌里 ResponseIterator = ResponseNavigator.Select("uri") ResponseIterator.MoveNext() _Uri = ResponseIterator.Current.Value '通过检查 ResponseIterator = ResponseNavigator.Select("checkedby") ResponseIterator.MoveNext() _Checkedby = ResponseIterator.Current.Value ...ETC...如何修复上面的损坏代码?或者:我是否偏离了轨道?有什么更好的方法?
【问题讨论】:
-
您有可用的 WSDL 吗? VS 应该能够为您自动为 Web 服务公开的数据类型生成类,因此您不必手动解析 SOAP 输出。
标签: .net xml vb.net soap xpath