我在这个 LINQ 语句中做错了什么?
我正在研究 Linq to xml,并且正在使用 linq 读取 xml 文件。我使用了以下方法,
public void getbooklist(string Path)
{
XDocument xdoc = XDocument.Load(Path);
var books = new book in xdoc.Elements("book")
select book;
}
我的 xml 文件如下所示,
<?xml version="1.0" encoding="utf-8" ?>
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>
An in-depth look at creating applications
with XML.
</description>
</book>
<book id="bk102">
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-12-16</publish_date>
<description>
A former architect battles corporate zombies,
an evil sorceress, and her own childhood to become queen
of the world.
</description>
</book>
</catalog>
当我尝试执行该方法时,出现错误
A new expression require ()、[] 或 {} 后键入
...我做错了什么?
I am studying Linq to xml and i am reading a xml file using linq.. I used the following method,
public void getbooklist(string Path)
{
XDocument xdoc = XDocument.Load(Path);
var books = new book in xdoc.Elements("book")
select book;
}
and my xml file looks like this,
<?xml version="1.0" encoding="utf-8" ?>
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>
An in-depth look at creating applications
with XML.
</description>
</book>
<book id="bk102">
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-12-16</publish_date>
<description>
A former architect battles corporate zombies,
an evil sorceress, and her own childhood to become queen
of the world.
</description>
</book>
</catalog>
and when i tried to execute the method i get an error
A new expression requires (), [], or {} after type
... What am i doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的代码应该是这样的:
You code should be something like this: