<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <br /> <asp:TextBox ID="TextBox2" runat="server">text2</asp:TextBox> <br /> <asp:TextBox ID="TextBox3" runat="server">text3</asp:TextBox> <input type="text" /> <br /> <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="GenerateXML" /> </div> </form> </body> </html>
private void GenerateXML() { string html; WebClient webClient = new WebClient(); string url = "http://HtmlPagetoXML/Default2.aspx"; using (Stream stream = webClient.OpenRead(new Uri(url))) using (StreamReader reader = new StreamReader(stream)) { html = reader.ReadToEnd(); } IHTMLDocument2 doc = (IHTMLDocument2)new HTMLDocument(); doc.write(html); XmlDocument document = new XmlDocument(); XmlElement root = document.CreateElement("controls"); foreach (IHTMLElement el in doc.all) { if (el.tagName != "!" && el.tagName != "HEAD" && el.tagName != "DOCTYPE" && el.tagName != "SCRIPT" && el.tagName != "HTML" && el.tagName != "STYLE" && el.tagName != "META" && el.tagName != "LINK" && el.tagName != "TITLE" && el.tagName != "FORM" && el.tagName != "BODY") { if (el.id != null) { if (el.getAttribute("type", 1) != null && el.getAttribute("type", 1).ToString() != "hidden") { XmlElement element = document.CreateElement(el.tagName); // element.InnerText = el.innerText; XmlElement elechild = document.CreateElement("ID"); elechild.InnerText = el.id; element.AppendChild(elechild); XmlElement elechild1 = document.CreateElement("Value"); XmlElement elechild2 = document.CreateElement("Type"); if (el.getAttribute("type", 1) != null) { elechild2.InnerText = el.getAttribute("type", 1).ToString(); element.AppendChild(elechild2); } if (el.getAttribute("value", 1) != null) { elechild1.InnerText = el.getAttribute("value", 1).ToString(); element.AppendChild(elechild1); } root.AppendChild(element); } } } } string xmlfileLocation = @"D:\Test1.xml"; XmlNode xmlNode = document.CreateNode(XmlNodeType.XmlDeclaration, "Test", ""); document.AppendChild(root); document.Save(xmlfileLocation); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)