public static string ToHtmlTableText(this DataTable table) { var tableElem = new HtmlElem("table"); // tr for the column heading of each column of the report. { var trElem = tableElem.AddElem("tr"); // <th> for each column. for( int ix = 0; ix < table.Columns.Count; ++ix) { var col = table.Columns[ix]; var thElem = trElem.AddText("th", col.ColumnName); } } // <tr> for each row of the report. for( int ix = 0; ix < table.Rows.Count; ++ix) { var row = table.Rows[ix]; var trElem = tableElem.AddElem("tr"); // td for each data item of the row. for( int jx = 0; jx < table.Columns.Count; ++jx) { var tdElem = trElem.AddText("td", row[jx].ToString( )); } } var tableText = tableElem.ToString(); return tableText; }
public string ToHtmlTableText( ) { var tableElem = new HtmlElem("table"); // tr for the column heading of each column of the report. { var trElem = tableElem.AddElem("tr"); // <th> for each column. foreach (var column in this.Columns) { var thElem = trElem.AddText("th", column.ColName); } } // <tr> for each row of the report. foreach (var row in this.Rows) { var trElem = tableElem.AddElem("tr"); // td for each data item of the row. foreach (var dataItem in row) { var tdElem = trElem.AddText("td", dataItem.Value); } } var tableText = tableElem.ToString(); return(tableText); }
public void gatherLinks(ref List <Post> filtered, ref List <Tuple <string, string, string> > links) { WebBrowser1.Navigate(string.Empty); HtmlDocument fakeDoc = WebBrowser1.Document; foreach (Post Post in filtered) { string text = Post.com; text = "<HTML><body>" + text + "</body></HTML>"; fakeDoc.Write(text); } HtmlElementCollection HtmlElems = fakeDoc.Links; foreach (HtmlElement HtmlElem in HtmlElems) { string str = HtmlElem.GetAttribute("href"); Uri uri = new Uri(str); string str2 = uri.Fragment; string[] parts = uri.AbsolutePath.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); if (string.IsNullOrEmpty(str2)) { str2 = parts[2]; } else { str2 = str2.Trim(new char[] { '#', 'p' }); } if (parts.Length == 3) { links.Add(new Tuple <string, string, string>(parts[0], parts[2], str2)); } } }
static async void Composite(string path) { WebCrawler crawler = WebCrawler.GetInstance(); HtmlStoreProxy proxy = new HtmlStoreProxy(); MyHtmlModel model = await proxy.GetMyHtmlModel(path); HtmlDocument htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(model.HTML); HtmlNode html = crawler.GetFirstNode("html", htmlDoc); var bodyNode = html.SelectSingleNode("//body"); var navigationNode = crawler.GetNode ( "class", "navbar navbar-expand-lg navbar-light fixed-top", htmlDoc ); var headerNode = crawler.GetNode ( "class", "masthead", htmlDoc ); var aboutSectionNode = crawler.GetNode ( "id", "about", htmlDoc ); var signupSection = crawler.GetNode ( "id", "signup", htmlDoc ); var contentOfsignupSection = crawler.GetFirstNode("body/section[3]/div[1]", htmlDoc); signupSection.RemoveAllChildren(); html.RemoveChild(bodyNode);//html tag is without body tag Console.WriteLine(html.OuterHtml); ////////////////Composite realization Composite.Component htmlComposite = new CompositeComponent ( new MyHtmlModel() { HTML = html.OuterHtml, Name = "WithoutBody" } ); htmlComposite.Node = html; bodyNode.RemoveAllChildren();//body tag is empty //composite components Composite.Component EmptyBody = new CompositeComponent ( new MyHtmlModel() { HTML = bodyNode.OuterHtml, Name = "EmptyBody" } ); EmptyBody.Node = bodyNode; //leaf HtmlElem navigation = new HtmlElem(new MyHtmlModel() { HTML = navigationNode.OuterHtml, Name = "NavBar" }); navigation.Node = navigationNode; //leaf HtmlElem header = new HtmlElem(new MyHtmlModel() { HTML = headerNode.OuterHtml, Name = "Header" }); header.Node = headerNode; //leaf HtmlElem AboutSection = new HtmlElem(new MyHtmlModel() { HTML = aboutSectionNode.OuterHtml, Name = "NavBar" }); AboutSection.Node = aboutSectionNode; //append children to body EmptyBody.Add(navigation); EmptyBody.Node.AppendChild(navigation.Node); EmptyBody.Add(header); EmptyBody.Node.AppendChild(header.Node); EmptyBody.Add(AboutSection); EmptyBody.Node.AppendChild(AboutSection.Node); htmlComposite.Add(EmptyBody); htmlComposite.Node.AppendChild(EmptyBody.Node); htmlComposite.Display();//displaying tree Console.WriteLine("--------------------htmlComposite html----------------"); Console.WriteLine(htmlComposite.Node.OuterHtml); //displaying node html EmptyBody.Remove(AboutSection); //remove child EmptyBody.Node.RemoveChild(AboutSection.Node); //remove node Console.WriteLine("--------------------htmlComposite html after remove----------------"); Console.WriteLine(htmlComposite.Node.OuterHtml);//displaying body without child EmptyBody.Add(AboutSection); EmptyBody.Node.AppendChild(AboutSection.Node); //add one more composite element Composite.Component signUpSectionComposite = new CompositeComponent (new MyHtmlModel() { HTML = signupSection.OuterHtml, Name = "EmptySignUpSection" }); signUpSectionComposite.Node = signupSection; //leaf HtmlElem signUpSectionContainer = new HtmlElem ( new MyHtmlModel() { HTML = contentOfsignupSection.OuterHtml, Name = "SignUpSectionContainer" } ); signUpSectionContainer.Node = contentOfsignupSection; signUpSectionComposite.Add(signUpSectionContainer); signUpSectionComposite.Node.AppendChild(signUpSectionContainer.Node); EmptyBody.Add(signUpSectionComposite); EmptyBody.Node.AppendChild(signUpSectionComposite.Node); htmlComposite.Display(); Console.WriteLine("--------------------htmlComposite html----------------"); Console.WriteLine(htmlComposite.Node.OuterHtml); htmlComposite.MyHtmlmodel.HTML = htmlComposite.Node.OuterHtml;//saving all html MyHtmlModel final = new MyHtmlModel() { HTML = htmlComposite.MyHtmlmodel.HTML, Name = "ResultOfComposition" }; try { GenericSerializer serializer = new GenericSerializer("res", @"E:\studying\education\6сем\трпз\lab5\Saves\"); serializer.BinarySerializing(FileMode.Create, final); serializer.DataContractSerialization(FileMode.Create, typeof(MyHtmlModel), final); } catch (Exception e) { } }