c# - XElement XML ToString malformed [ ] -
so m parsing xml. create xelement , run tostring() method. @ results , wrong.
<root>[elementname, elementvalue ]</root>
when should like
<root> <data name="name"> <value>value</value> </data> </root>
this really weird. ive used xml plenty of times , have never run this. have looked on web , cant find anything. when step through xdocument creation process tostring() each element correct. going on ? how can troubleshoot ?
here code
string writexml(dictionary<string, string> dic) { var root = new xelement("root"); foreach (var pair in dic) { var element = new xelement("data", pair.value); element.add(new xattribute("name", pair.key)); root.add(pair); } var doc = new xdocument(new xdeclaration("1.0", "utf-8", null), root); var s = doc.tostring(); console.writeline(s); return doc.tostring(); }
Comments
Post a Comment