读取XML文件(API)时出错 [英] Error reading XML File (API)

查看:130
本文介绍了读取XML文件(API)时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用vb.net中的转发器控件从xml文件(API)读取数据。但我收到以下错误:XmlNodeList'是一个类型,不能用作表达式。 

该错误指向以下代码中的这一行:

XmlNodeList nodes = doc.SelectNodes(products / product)
任何人都可以帮忙修复这个错误?

代码如下所示:

< Script runat = server >
sub Page_Load
if Not Page.IsPostBack then Dim doc as XmlDocument = new XmlDocument()
doc.Load(这是url链接)
XmlNodeList nodes = doc.SelectNodes(products / product)
rpMyRepeater.DataSource = nodes
rpMyRepeater.DataBind()
end if if
end sub
< / script >

< html >
< body >
< asp:repeater id = rpMyRepeater runat = 服务器 >
< HeaderTemplate > >
< / HeaderTemplate >
< ItemTemplate >

<%#((System.Xml.XmlNode)Container.DataItem).Attributes [ description]。值%>
< span class =code-pagedirective><%#((System.Xml.XmlNode)Container.DataItem).InnerXml %>

< / ItemTemplate >
< FooterTemplate > ;
< / FooterTemplate >
< / asp:repeater >

解决方案

有可能,你所谓的这是url链接不是一个有效的XML文档,很可能,它没有格式良好。您可以在任何Web浏览器中加载它;它会告诉你文件中的bug在哪里。



-SA


你'重新混合VB和C#语法。在VB中,声明必须是:

  Dim 节点作为 XmlNodeList = doc.SelectNodes(  products / product


I am trying to read data from an xml file (API) using the repeater control in vb.net. but I am getting the following error: XmlNodeList' is a type and cannot be used as an expression. 

The error is pointing at this line from the code below:

XmlNodeList nodes = doc.SelectNodes("products/product")
Can anyone please help fix this error?

The code is shown below:

<Script runat="server">
sub Page_Load
if Not Page.IsPostBack then Dim doc  as XmlDocument = new XmlDocument()
doc.Load("this is the url link")
 XmlNodeList  nodes  = doc.SelectNodes("products/product")
rpMyRepeater.DataSource = nodes
rpMyRepeater.DataBind()
end if
end sub
</script>

<html>
<body>
<asp:repeater id="rpMyRepeater" runat="server">
<HeaderTemplate>>
</HeaderTemplate>
   <ItemTemplate>

<%# ((System.Xml.XmlNode)Container.DataItem).Attributes["description"].Value %>
 <%# ((System.Xml.XmlNode)Container.DataItem).InnerXml %>

   </ItemTemplate>
   <FooterTemplate>
   </FooterTemplate>
</asp:repeater>

解决方案

Chances are, what you called "this is the url link" is not a valid XML document, most likely, it is not well-formed. You can load it in any Web browser; it will show you where the bug in the file is.

—SA


You're mixing VB and C# syntax. In VB, the declaration needs to be:

Dim nodes As XmlNodeList = doc.SelectNodes("products/product")


这篇关于读取XML文件(API)时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆