0
votes

<?xml version="1.0" encoding="UTF-8"?>
<div class="contentLeft">

<h1>Hello</h1>

    <ul id="resultlist" class="stories">
        <li>
          
        </li>
    </ul>

</div>

I have the following XML file, and I would like to read the "li" entry as follows:

var doc = new HtmlDocument();
doc.Load(path);

var query = "//div[contains(@class,'contentLeft')]//ul";
var childNodes = doc.DocumentNode.SelectSingleNode(query).ChildNodes;

Now I should have an entry in the list - but I have three! enter image description here

Actually I only expect the "li" entry, does anyone of you know where the two "#text" entries come from?

Here are the dontnetfiddle.net link to my Problem:

DotNetfiddle.net

1

1 Answers

0
votes

There are many ways to solve it:

  1. Modify your XPATH
  2. Use LINQ: nodes.ChildNodes.Where(_ => _.NodeType != HtmlNodeType.Text); or nodes.ChildNodes.Where(_ => _.Name.Equals("li")).

I don't remember exactly but 1 of them should work.