【发布时间】:2019-05-10 17:07:40
【问题描述】:
我有一个错误,例如:“System.Xml.dll 中发生‘System.Xml.XmlException’类型的异常,但未在用户代码中处理”
在我的程序中,我使用来自该站点的服务引用:http://www.oorsprong.org/websamples.countryinfo/CountryInfoService.wso,并且在运行程序时,它会阻止我使用字符串。
XML 文件:(我只想取 sName)
<ArrayOftContinent>
<tContinent>
<sCode>AF</sCode>
<sName>Africa</sName>
</tContinent>
</ArrayOftContinent>
代码如下:
org.oorsprong.www.CountryInfoService myWS3 = new org.oorsprong.www.CountryInfoService();
string str = Convert.ToString(myWS3.ListOfContinentsByName());
XmlDocument doc = new XmlDocument();
doc.LoadXml(str); /*It stops me here*/
你能帮我解决这个问题吗? 提前致谢!
【问题讨论】:
-
那么,
str中的字符串是什么样的? -
str 是一个 XML 字符串,它将以 xml 格式保存所有大洲 @LasseVågsætherKarlsen
-
@Christina 请复制该字符串中的实际 xml 文本,并将其粘贴到您的问题中,以便我们查看并使用它测试您的代码。
-
您说它是一个 xml 字符串,但显然
XmlDocument不同意,您需要粘贴您的 XML 或生成一个 minimal reproducible example 供我们尝试。 -
那个xml是
str的内容吗?您验证了这个?我怀疑的是,您实际上是从您在那里声明的那个客户端获取了一些对象的列表,并且您的ToString方法将其转换为类似"System.Collections.Generic.List'1[org.oorsprong.www.Country]"
标签: c# asp.net xml xml-parsing xmldocument