HtmlAgilityPack.HtmlWeb.LoadHtmlAsXml C# (CSharp) Method

LoadHtmlAsXml() public method

Loads an HTML document from an Internet resource and saves it to the specified XmlTextWriter.
public LoadHtmlAsXml ( string htmlUrl, XmlTextWriter writer ) : void
htmlUrl string The requested URL, such as "http://Myserver/Mypath/Myfile.asp".
writer System.Xml.XmlTextWriter The XmlTextWriter to which you want to save to.
return void
        public void LoadHtmlAsXml(string htmlUrl, XmlTextWriter writer)
        {
            HtmlDocument doc = Load(htmlUrl);
            doc.Save(writer);
        }

Usage Example

Example #1
0
    public static XmlDocument GetHtmlAsXml()
    {
        //Set up an in-memory stream to hold the HTML.
        MemoryStream stream = new MemoryStream();
        XmlTextWriter writer = new XmlTextWriter(stream, Encoding.UTF8);

        //Grab HTML over the web and convert to XML.
        HtmlWeb web = new HtmlWeb();
        web.LoadHtmlAsXml("http://haacked.com/Demos/screen.html", writer);

        //Now read from that in-memory stream
        //into a new XmlDocument class.
        XmlDocument xml = LoadFromStream(stream);
        return xml;
    }