【发布时间】:2011-07-29 14:14:16
【问题描述】:
问题是如果节点包含命名空间/属性,我将无法获得任何结果。这是代码:
Dim xmlFromDisk = XDocument.Load("customers.xml")
Dim ukCustomers = <ukCustomers>
<%= From cust In xmlFromDisk...<Customer> _
Where cust.<Country>.Value = "UK" _
Select cust %>
</ukCustomers>
当我有以下 customers.xml 时,查询有效:
<?xml version="1.0" encoding="utf-8"?>
<Customers>
<Customer>
<CustomerID>ALFKI</CustomerID>
<CompanyName>Alfreds Futterkiste</CompanyName>
<Country>UK</Country>
</Customer>
</Customers>
当我有以下 customers.xml 时,查询不起作用:
<?xml version="1.0" encoding="utf-8"?>
<Customers xmlns="http://tempuri.org/">
<Customer>
<CustomerID>ALFKI</CustomerID>
<CompanyName>Alfreds Futterkiste</CompanyName>
<Country>UK</Country>
</Customer>
</Customers>
唯一的区别是客户元素中的命名空间 xmlns="http://tempuri.org/"。
【问题讨论】:
标签: linq linq-to-xml