c# - Rewrite XMLDocument to use namespace prefix -


i have xmldocument which, when save file, repeats namespace on of elements, in

<test>     <test xmlns="http://example.com/schema1">        <name xmlns="http://example.com/schema2">xyz</name>       <addressinfo xmlns="http://example.com/schema2">         <address>address</address>         <zipcode>zzzz</zipcode>       </addressinfo>        ... 

is possible amend file uses namespace prefix throughout document, ie like

<test xmlns="http://example.com/schema1" xmlns:p="http://example.com/schema2"  >   <p:name>xyz</p:name>  <p:addressinfo">    <p:address>address</p:address>    <p:zipcode>zzzz</p:zipcode>  </p:addressinfo>          ... 

i have tried adding

   doc.documentelement.setattribute("xmlns:p", "http://example.com/schema2"); 

but whilst adds namespace header, main body of file unchanged.

you can change xmlelement.prefix property value :

doc.documentelement.setattribute("xmlns:p", "http://example.com/schema2"); //xpath selecting elements in specific namespace : var xpath = "//*[namespace-uri()='http://example.com/schema2']"; foreach(xmlelement node in doc.selectnodes(xpath)) {     node.prefix = "p"; } doc.save("path_to_file.xml"); 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -