简体   繁体   中英

Unable to get elements using XPathSelectElements

I have the Xelement as follows.

<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");

I have tried the above code, to get the array of term element. But i am getting null as the result. I have tried the code in XML tools and i got the result.But, still i am unable to get.

May i kindly know, whether i am missing something or where i am mistaking?

Thanks in advance.

try this :

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

what is XRoot ? you should call XPathSelectElements() on your xelement...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM