Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have an XML document i am trying to parse with HTML Agility Pack using XPath. This is my code for getting to the elements
C#
HtmlDocument htmldoc = new HtmlDocument();
htmldoc.Load(fileName);
HtmlNodeCollection nodes = htmldoc.DocumentNode.SelectNodes("feed/l");

This is my XML document
XML
<?xml version="1.0" encoding="UTF-8"?>
<feed>
<tm>5701</tm>
<tp>1141</tp>
<pnr>1</pnr>
<l type="TEXT">
<ca>
<c id="21">JA</c>
</ca>
<pts>
<pt id="5">DO</pt>
</pts>
<od>MA 99</od>
<osd>2014-02-21</osd>
<od>2014-02-22</od>
<cu>url</cu>
<ip>ip</ip>
<ai>3184</ai>
<an>com</an>
<n id="1">US n</n>
</l>
<l type="TEXT">
<ca>
<c id="21">JA</c>
</ca>
<pts>
<pt id="5">DO</pt>
</pts>
<od>MA 99</od>
<osd>2014-02-21</osd>
<od>2014-02-22</od>
<cu>url</cu>
<ip>ip</ip>
<ai>3184</ai>
<an>com</an>
<n id="1">US n</n>
</l>
<l type="TEXT">
<ca>
<c id="21">JA</c>
</ca>
<pts>
<pt id="5">DO</pt>
</pts>
<od>MA 99</od>
<osd>2014-02-21</osd>
<od>2014-02-22</od>
<cu>url</cu>
<ip>ip</ip>
<ai>3184</ai>
<an>com</an>
<n id="1">US n</n>
</l>
<l type="TEXT">
<ca>
<c id="21">JA</c>
</ca>
<pts>
<pt id="5">DO</pt>
</pts>
<od>MA 99</od>
<osd>2014-02-21</osd>
<od>2014-02-22</od>
<cu>url</cu>
<ip>ip</ip>
<ai>3184</ai>
<an>com</an>
<n id="1">black US n </n>
</l>

</feed>

I am trying to get all the node that are children of "l" and their children but my xpath brings nodes back with "l" as a collection but the children are null. the nodes i am looking for grouped by "l are these
XML
<ca>
<c id="21">JA</c>
</ca>
<pts>
<pt id="5">DO</pt>
</pts>
<od>MA 99</od>
<osd>2014-02-21</osd>
<od>2014-02-22</od>
<cu>url</cu>
<ip>ip</ip>
<ai>3184</ai>
<an>com</an>
<n id="1">black US n </n>

but there are no children. Please help my xpath seems to be correct
Posted
Updated 4-Apr-14 4:51am
v3

1 solution

Try using
htmldoc.DocumentNode.SelectNodes("//l");
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900