gpt4 book ai didi

c# - 从 xml 文件中检索元数据

转载 作者:太空宇宙 更新时间:2023-11-03 14:17:54 25 4
gpt4 key购买 nike

我需要从多个 xml 文件中检索元数据。 xml文件的结构如下:

<songs>
<song_title> some title </song_title>
<classification> some classification </classification>
<song_text> some text </song_text>
<singer>
<sing> singer's name </sing>
<gender> gender </gender>
<bornYear> year </bornYear>
<livePlace> live place </livePlace>
<liveArea> live area </liveArea>
</singer>
</songs>

用户选择搜索条件 - 居住地点或居住区域。然后他输入他搜索的地点或区域的名称。我需要找到并显示歌曲的链接,这些歌曲的元数据中包含用户输入的地点或区域。我正在使用 .NET 3.5

最佳答案

这个答案更像是一个指针......

您可以使用 LINQ to XML来完成这个任务。

什么是 LINQ to XML?

LINQ to XML is a LINQ-enabled, in-memory XML programming interface that enables you to work with XML from within the .NET Framework programming languages.

LINQ to XML is like the Document Object Model (DOM) in that it brings the XML document into memory. You can query and modify the document, and after you modify it you can save it to a file or serialize it and send it over the Internet. However, LINQ to XML differs from DOM: It provides a new object model that is lighter weight and easier to work with, and that takes advantage of language improvements in Visual C# 2008.

然后您可以使用 LINQ 查询表达式搜索和操作任何 XML 文档元素,如下例所示:

IEnumerable<XElement> partNos =
from item in purchaseOrder.Descendants("Item")
where (int) item.Element("Quantity") *
(decimal) item.Element("USPrice") > 100
orderby (string)item.Element("PartNumber")
select item;

关于c# - 从 xml 文件中检索元数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6179227/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com