使用 LINQ 搜索 XML
下面是我的 XML 文件。基于
,我需要获取
的所有节点值。
<?xml version='1.0' encoding='utf-8' ?>
<All>
<Customers>
<Customer>
<Name> Brisbane </Name>
<age> 18 </age>
<id> 1234 </id>
<type> owner </type>
</Customer>
<details>
<address> 123,Brisbane </address>
<location> Indonesia </location>
</details>
<contact>
<phone> 123456789 </phone>
<fax> 12548976 </fax>
</contact>
</Customers>
<Customers>
<Customer>
<Name> Manila</Name>
<age> 16 </age>
<id> 1200 </id>
<type> seller</type>
</Customer>
<details>
<address> Rich Street </address>
<location> Fabia </location>
</details>
<contact>
<phone> 987456321</phone>
<fax> 23654897 </fax>
</contact>
</Customers>
</All>
例如,在上面的例子中有两种类型:
- 业主
- 卖家。
因此,如果我选择“所有者”,我需要获取如下详细信息。
Brisbane
18
1234
123,Brisbane
Indonesia
123456789
12548976
如果我选择“卖家”,我需要获取如下详细信息。
Manila
16
1200
Rich Street
Fabia
987456321
23654897
那么我该怎么做呢?对此有什么示例代码吗?
The below is my XML file. Based on the <type>
, I need to get all the node values of <customers></customers>
.
<?xml version='1.0' encoding='utf-8' ?>
<All>
<Customers>
<Customer>
<Name> Brisbane </Name>
<age> 18 </age>
<id> 1234 </id>
<type> owner </type>
</Customer>
<details>
<address> 123,Brisbane </address>
<location> Indonesia </location>
</details>
<contact>
<phone> 123456789 </phone>
<fax> 12548976 </fax>
</contact>
</Customers>
<Customers>
<Customer>
<Name> Manila</Name>
<age> 16 </age>
<id> 1200 </id>
<type> seller</type>
</Customer>
<details>
<address> Rich Street </address>
<location> Fabia </location>
</details>
<contact>
<phone> 987456321</phone>
<fax> 23654897 </fax>
</contact>
</Customers>
</All>
For example, in the above example there are two types:
- owner
- seller.
So if I choose "owner" I need to get the details as follows
Brisbane
18
1234
123,Brisbane
Indonesia
123456789
12548976
So if I choose "seller" I need to get the details as follows.
Manila
16
1200
Rich Street
Fabia
987456321
23654897
So how do I do this? What would some sample code for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,假设 XML 称为“doc”。
OK say the XML is called "doc".