Linq to XML - 查询不返回任何内容
我有一个 XML 文件,当我运行 LINQ 查询时,for 循环中不会返回任何内容。
<?xml version="1.0" encoding="utf-8"?>
<ReadOrderResponseType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Status xmlns="urn:mysite:apis">Success</Status>
<TimeStamp xmlns="urn:mysite:apis">2010-07-25T15:26:49.1150235Z</TimeStamp>
<StoreUrl xmlns="urn:mysite:apis">http://XYZ.COM</StoreUrl>
<PageResponse xmlns="urn:mysite:apis">
<Page>1</Page>
<Size>10</Size>
<TotalSize>18033</TotalSize>
<HasMore>true</HasMore>
</PageResponse>
<OrderList OrderId="20147184" OrderNumber="20100560" xmlns="urn:mysite:apis">
<Archived>false</Archived>
<CreateDate>2010-07-25T01:37:04.067Z</CreateDate>
</OrderList>
</ReadOrderResponseType>
VB.NET:
Dim document As XDocument = XDocument.Parse(myOrders.xml)
Dim query = From O In document.Root.Elements("OrderList") _
Select New With _
{ _
.Archived= O.Element("Archived").Value, _
.Status = O.Element("CreateDate").Value _
}
For Each Order In query
Console.WriteLine(Order.Archived)
Console.ReadLine()
Next
它甚至不进入 for 循环。我做错了什么?
I have a XML file on which when I run a LINQ query returns nothing in the for loop.
<?xml version="1.0" encoding="utf-8"?>
<ReadOrderResponseType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Status xmlns="urn:mysite:apis">Success</Status>
<TimeStamp xmlns="urn:mysite:apis">2010-07-25T15:26:49.1150235Z</TimeStamp>
<StoreUrl xmlns="urn:mysite:apis">http://XYZ.COM</StoreUrl>
<PageResponse xmlns="urn:mysite:apis">
<Page>1</Page>
<Size>10</Size>
<TotalSize>18033</TotalSize>
<HasMore>true</HasMore>
</PageResponse>
<OrderList OrderId="20147184" OrderNumber="20100560" xmlns="urn:mysite:apis">
<Archived>false</Archived>
<CreateDate>2010-07-25T01:37:04.067Z</CreateDate>
</OrderList>
</ReadOrderResponseType>
VB.NET:
Dim document As XDocument = XDocument.Parse(myOrders.xml)
Dim query = From O In document.Root.Elements("OrderList") _
Select New With _
{ _
.Archived= O.Element("Archived").Value, _
.Status = O.Element("CreateDate").Value _
}
For Each Order In query
Console.WriteLine(Order.Archived)
Console.ReadLine()
Next
It does not even go inside the for loop. What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要一个命名空间限定符。尝试类似的方法:
You need a namespace qualifier. Try something like: