开发者

Parsing XML returned from Webserver vb.net

I get this XML data from my web application

<api_result>
    <send_info>
    <eventid>0</eventid>
    </send_info>
    <call_result>
        <result>False</result>
        <error>No data to send</error>
    </call_result>
</api_result>

how do i get the <result> content and the content, i.e false and error?

This is what i did:

Dim xmldoc 开发者_运维问答As New XmlDataDocument()
    `xmldoc.LoadXml(sTempUrl)`    <-- this line gives error
    Dim xmlnode As XmlNodeList = xmldoc.GetElementsByTagName("error") 
    sError = xmlnode(0).ChildNodes.Item(0).InnerText.Trim()

however I am getting this error in the bold line:

Cannot load XmlDataDocument if it already contains data. Please use a new XmlDataDocument.


You should use empty XmlDataDocument when loading from file or string, so I guess you problem is here. As I remember .Net 2 supports Select method, which is more elegant way to get element from xml. see XmlDataDocument.Select, but this is not your case, just create new XmlDataDocument on loading.

Hope this helps

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜