Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing to an existing xml document

Status
Not open for further replies.

verak

Programmer
Feb 12, 2004
2
NO
Hi

I'm trying to writ to an existing xml document, but I have a lite problem:

Why does this code add 'xmlns = ""' to the added xml code?? and how does I get rid of it??


The XML file:
-----------------------------------------------------------
<root xmlns=&quot; <Node ID=&quot;001&quot;>
<Value1>3</Value1>
<Value2>true</Value2>
</Node>
<!-- here coms the inserted xml code --!>
<Node ID=&quot;002&quot; xmlns=&quot;&quot;>
<Value1>9</Value1>
<Value2>false</Value2>
</Node>
</root>
------------------------------------------------------------

The C# code:
------------------------------------------------------------
XmlNode currNode;
XmlDocument doc = new XmlDocument();

doc.Load(reader);
XmlDocumentFragment docFrag = doc.CreateDocumentFragment();

docFrag.InnerXml =
&quot;<Node ID='002'>&quot;+
&quot;<Value1>&quot;+&quot;9&quot;+&quot;</Value1>&quot;+
&quot;<Value2>&quot;+&quot;false&quot;+&quot;</Value2>&quot;+
&quot;</Node>&quot;

currNode = doc.DocumentElement;

currNode.AppendChild(docFrag);

reader.Close();

doc.Save(&quot;XMLtest.xml&quot;);

------------------------------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top