1

I have html code like that:

<div class="topright">
    <a href="" TARGET="_parent" title="News Letter" >
       <img border="none" src="/images/newsletter-button.gif' alt="News Letter" />
     </a>
</div>

I am developing function findvalue in C#:

if (line.Contains("title"))
{
    sTitle = findvalue("title", line);
}

findvalue function is simple string opreations function which work like that for this line <a href="" TARGET="_parent" title="News Letter" > find function will retrun News Letter value, similarly I will get value of other attributes like href, src atc

शेखर
  • 17,412
  • 13
  • 61
  • 117
khawarPK
  • 2,179
  • 4
  • 20
  • 31
  • 2
    Please specify reason you are doing it (education, assignment, code to be used). Depending on the reson answers will be different. Note that HTMLAgility pack is traditional answer to this question... – Alexei Levenkov Apr 19 '13 at 05:25
  • for my project but for one scenario on a single page. – khawarPK Apr 19 '13 at 05:29
  • Than most likely you want to use existing library - it does not look like you are interested in learning all intricacies of parsing markup yourself. – Alexei Levenkov Apr 19 '13 at 05:36
  • 1
    If you are wanting to parse the HTML, your best bet will be to use a library, like [the HTML Agility Pack](http://htmlagilitypack.codeplex.com/) – Kevin Anderson Apr 19 '13 at 05:25
  • For one scenario on a single page, should I use this library or my custom function? – khawarPK Apr 19 '13 at 05:29
  • Much better is to use HtmlAgilityPack without waste time n effort,Thank you guys... – khawarPK Apr 19 '13 at 08:53

2 Answers2

1

You can use XML schema related classes for the same.

using System;
using System.IO;
using System.Xml;

public class Sample
{

    public static void Main()
    {

        XmlDocument doc = new XmlDocument();
        doc.LoadXml("<input title='Meluha' Value='1-861001-75-7'>" +
                    "<title>The Imortals of Meluha</title>" +
                    "</input>");

        XmlNode root = doc.DocumentElement;

        XmlNode value = doc.SelectNodes("//input/@value")[0];

        Console.WriteLine("Inner text: " + value.InnerText);

    XmlNode value = doc.SelectNodes("//title/@value")[0];

    Console.WriteLine("Title text: " + value.InnerText);
     } 
}
Jigar Pandya
  • 6,004
  • 2
  • 27
  • 45
0

Much better is try to use HtmlAgilityPack without waste time n effort,Thank you guys...

khawarPK
  • 2,179
  • 4
  • 20
  • 31