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

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -