Linq to XML, C# -
i have xml in xdocument
object (linq xml). need add namespace each xelement/node in xdocument.
i dont want add in below way. beceause have xml in xdoc.
xdocument xdoc = new xdocument( new xelement(ns + "root", new xelement(ns + "person", new xattribute("id", 1), new xelement(ns + "firstname", "jack"),
below format have
<root> <person>1</person> <firstname>jack</firstname> </root>
i want convert below format
<emp:root> <emp:person>1</emp:person> <emp:firstname>jack</emp:firstname> </emp:root>
foreach (var node in xdoc.descendants()) { node.name = ns + node.name.localname; }
that should work:
side note namespace appear on root node.
Comments
Post a Comment