We help IT Professionals succeed at work.
Get Started

c# using HtmlAgilityPack or xpath ... html data

216 Views
Last Modified: 2015-03-02
I have test1.html in a folder and want to capture its embedded data shown on the image below:outputThe code I have now here is not producing what I need. Please see below for the code and the result it is producing:
           
            HtmlDocument hdoc = new HtmlDocument();
            HtmlNode abcTable;
            HtmlNodeCollection tableCells;

            hdoc.Load("test1.html");
            abcTable = hdoc.DocumentNode.SelectSingleNode("//table[@summary='ABC']");
            tableCells = abcTable.SelectNodes("//td");

            foreach (HtmlNode cell in tableCells)
            {
                Response.Write(cell.InnerText);
            }

The result using the above code:
Field1 Value1 Field6 Value6 Field2 Value2 Field7 Value7 Field3 Value3 Field8 Value8 Field4 Value4 Field9 Value9 Field5 Value5 Field10 Value10

Field11  Field12 Field13 Field14 Field15 Field16 Field17 Field18 Field19 
Valu11  Valu12  Valu13                             Valu16  Valu17   

Field1 Value1 Field6 Value6 Field2 Value2 Field7 Value7 Field3 Value3 Field8 Value8 Field4 Value4 Field9 Value9 Field5 Value5 Field10 Value10 

Field1 Value1 Field6 Value6 Field2 Value2 Field7 Value7 Field3 Value3 Field8 Value8 Field4 Value4 Field9 Value9 Field5 Value5 Field10 Value10 

Field11  Field12 Field13 Field14 Field15 Field16 Field17 Field18 Field19
Valu11  Valu12  Valu13                             Valu16  Valu17

Open in new window

Comment
Watch Question
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2015
Commented:
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE