i have log file this..
this segment 1 ============================ <mainelement><element1>10-10-2013 10:10:22.444</element1><element2>1111</element2> <element3>message 1</element3></mainelement> <mainelement><element1>10-10-2013 10:10:22.555</element1><element2>1111</element2> <element3>message 2</element3></mainelement> segment 2 ============================ <mainelement><element1>10-11-2012 10:10:22.444</element1><element2>2222</element2> <element3>message 1</element3></mainelement> <mainelement><element1>10-11-2012 10:10:22.555</element1><element2>2222</element2> <element3>message 2</element3></mainelement>
how can read datatable
excluding data this segment 1
, this segment 2
, ======
lines completely.
i have datatable
columns "element1", "element2", "element3"
, fill details content between tags in order of print of line.
it should not change sequence of order of records in table while inserting.
htmlagilitypack seems tool need:
using htmlagilitypack; class program { static void main(string[] args) { var doc = new htmldocument(); doc.load("log.txt"); var dt = new datatable(); bool hascolumns = false; foreach (htmlnode row in doc .documentnode .selectnodes("//mainelement")) { if (!hascolumns) { hascolumns = true; foreach (var column in row.childnodes .where(node => node.gettype() == typeof(htmlnode))) { dt.columns.add(column.name); } } dt.rows.add(row.childnodes .where(node => node.gettype() == typeof(htmlnode)) .select(node => node.innertext).toarray()); } } }
Comments
Post a Comment