Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 03, 2013 12:09 AM by Decker Dong - MSFT
Member
122 Points
228 Posts
Feb 01, 2013 05:32 AM|LINK
objIOM.PanicRange = lineItems[14]; XElement xe = XElement.Parse(objIOM.PanicRange); if (objIOM.PanicRange.Contains("referencerange")) { xe.FirstNode.ReplaceWith("panicrange"); }
The lineItem[14] contains
<referenceranges><referencerange> <property value="both" type="common"> <btw value="both">100 - 200</btw></property> </referencerange></referenceranges>
now i have to replace referencerange with panic range.The code above is not working.
Contributor
2626 Points
526 Posts
Feb 01, 2013 05:39 AM|LINK
http://stackoverflow.com/questions/5820143/how-can-i-update-replace-an-element-of-an-xelement-from-a-string
All-Star
118619 Points
18779 Posts
Feb 03, 2013 12:09 AM|LINK
shobana raja now i have to replace referencerange with panic range.The code above is not working.
Hi,
You can try to rename the specific node's name by doing this:
XDocument doc = XDocument.Load("XMLFile1.xml"); var result = doc.Descendants("referencerange").First(); result.Name = "panicrange"; doc.Save("d:\\try.xml");
shobana raja
Member
122 Points
228 Posts
replacing element
Feb 01, 2013 05:32 AM|LINK
objIOM.PanicRange = lineItems[14];
XElement xe = XElement.Parse(objIOM.PanicRange);
if (objIOM.PanicRange.Contains("referencerange"))
{
xe.FirstNode.ReplaceWith("panicrange");
}
The lineItem[14] contains
<referenceranges><referencerange>
<property value="both" type="common">
<btw value="both">100 - 200</btw></property>
</referencerange></referenceranges>
now i have to replace referencerange with panic range.The code above is not working.
priyankmtr
Contributor
2626 Points
526 Posts
Re: replacing element
Feb 01, 2013 05:39 AM|LINK
http://stackoverflow.com/questions/5820143/how-can-i-update-replace-an-element-of-an-xelement-from-a-string
(Mark as Answer If you find helpful)
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: replacing element
Feb 03, 2013 12:09 AM|LINK
Hi,
You can try to rename the specific node's name by doing this:
XDocument doc = XDocument.Load("XMLFile1.xml"); var result = doc.Descendants("referencerange").First(); result.Name = "panicrange"; doc.Save("d:\\try.xml");