copying a node and saving it as a new xml file c#
im a newbie and this is my very first question on stackoverflow so bear
with me please.
I have the following xml file
<?xml version="1.0" encoding="utf-8"?>
<items>
<superitem>
<item id="10" name="Ten"
description="This is number ten">
<attribute name="weight" value="1" />
<attribute name="capacity" value="80" />
</item>
<item id="20" name="Twenty"
description="This is might be number twenty">
<attribute name="weight" value="1" />
<attribute name="opaque" value="11" />
<uncertain>
<uncertainity name="might" level="Eighty Twenty."/>
</uncertain>
</item>
</superitem>
</items>
And in the code I am trying to copy the node with id = 20
newItem.SelectSingleNode("/items/superitem/item[@id='20']")
And to save that only node to another xml file. So I'm trying to get an
xml like this
<?xml version="1.0" encoding="utf-8"?>
<items>
<superitem>
<item id="20" name="Twenty"
description="This is might be number twenty">
<attribute name="weight" value="1" />
<attribute name="opaque" value="11" />
<uncertain>
<uncertainity name="might" level="Eighty Twenty."/>
</uncertain>
</item>
</superitem>
</items>
I did a try by importing the node to an xml file after the last child of
that xml and I could do that. What if I need a new xml file to be created
with only that node? Output xml to be exactly like I have mentioned
above??
No comments:
Post a Comment