gpt4 book ai didi

c# - 无法使用 XPathSelectElements 获取元素

转载 作者:行者123 更新时间:2023-12-03 17:32:59 28 4
gpt4 key购买 nike

我有如下的Xelement。

<root type="object">
<meta type="object">
<disclaimer type="string">XXXXX</disclaimer>
<license type="string">http://open.fda.gov/license</license>
<last_updated type="string">2015-05-31</last_updated>
</meta>
<results type="array">
<item type="object">
<term type="string">Oxygen</term>
<count type="number">397</count>
</item>
<item type="object">
<term type="string">Ibuprofen</term>
<count type="number">301</count>
</item>
</results>
 IEnumerable<XElement> data = XRoot.XPathSelectElements("/root/results/item/term");

我已经尝试了上面的代码,以获取术语元素的数组。但结果我得到了空值。我已经尝试过 XML 工具中的代码,我得到了结果。但是,我仍然无法得到。

请问我是否遗漏了什么或我在哪里弄错了?

提前致谢。

最佳答案

试试这个 :

IEnumerable<XElement> data = XRoot.XPathSelectElements("root/results/item/term");

什么是 XRoot ?您应该调用 XPathSelectElements()在你的 xelement...

关于c# - 无法使用 XPathSelectElements 获取元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31265514/

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