xml - How can i read the text inside the node of an example in C#? -
this xml want read.
<server servername="sp-swd-t01"> nodes there </server>
i want read servername inside server how can read it.please help.
this code
xmlreadersettings readersettings = new xmlreadersettings(); readersettings.ignorecomments = false; xmlreader xmlrdr = xmlreader.create(strfilepath, readersettings); // parse file while (xmlrdr.read()) { switch (xmlrdr.nodetype) { case xmlnodetype.element: // may need capture last element provide context // comments come across... copy xmlrdr.name, etc. break; case xmlnodetype.comment: messagebox.show(xmlrdr.name); break; case xmlnodetype.text: //display text in each element. //console.writeline(reader.value); break; case xmlnodetype.endelement: //display end of element. //console.write("</" + reader.name); //console.writeline(">"); break; } }
thanks
try this
string xml = @"<server servername=""sp-swd-t01"">some nodes there</server>"; xmldocument doc = new xmldocument(); doc.loadxml(xml); string servername = doc.selectsinglenode("/server").attributes["servername"].value;
Comments
Post a Comment