jason jason - 19 days ago 7
C# Question

Get list element when HTML Parsing

I have a piece of HTML like this :

<li class="myclass">
<ul class="myclass2">
<li><span>Name1</span><span>Value1</span></li><li><span>Name2</span><span>Value2</span></li><li><span>Name3</span><span>Value3</span></li>
</ul>
</li>


I'm trying to parse this HTML like this using HTML Agility Pack :

var values = mydetails.DocumentNode.QuerySelector(".myclass").QuerySelector("ul").InnerHtml;


This gives me this part :

<li><span>Name1</span><span>Value1</span></li><li><span>Name2</span><span>Value2</span></li><li><span>Name3</span><span>Value3</span></li>


But I don't know how to go further, I need Names and Values but I don't know how to get them. Can you show me a way to do it? Thanks.

Answer

You should give your items an html-id, then it should be very easy to get this element in javascript. I don't know your framework, but in others this is very easy, for example in jQuery: $("#id")

Comments