xml - Get all nodes and values without knowing the nodes name and level C# -
i have 15,000 xml in form of string
. each of xml has average of 1000 nodes.
i not know nodes name, , hierarchical level of xml. each xml, need parse them list<string> elements
, list<string> values
.
in case parent , child nodes present, parent node added list<string> elements
, null
or empty string added list<string> values
what possible ways of achieving so?
edited: supposed need know how parse 1 xml, , can loop same method 15,000 records.
p/s: thought of using dictionary
or multi-dimensional list
have <key><value>
pair, wasn't approved because affect other application significantly. has list
of elements , list
of values
you can use linq nodes xml. you'll need add using system.xml.linq;
parsing class, can grab data this.
string xml = "your xml string" var myxmldata = xelement.parse(xml); //get names of nodes var allnames = (from e in myxmldata.descendants() select e.name.localname).tolist(); //get values of each node - empty string nodes children var allelements = (from e in myxmldata.descendants() select (e.haselements ? "" : e.value)).tolist();
this give 2 list<string>
objects corresponding names , values xml.
Comments
Post a Comment