I tried using XMldocument and Xdoc for this but not getting the entire node.Also i want to replace the entire
Token node with a different Token node from another XML.
Below you can find DocumentPropertites , and replace the value in the subnode in it.
for example ,set the Title value from "title" to "hello".
// load the xml to memory XElement ex = XElement.Load(Server.MapPath("test.xml")); //get the namespace in your xml file,so that you can find the DocumentProperties
XNamespace xn = ex.GetNamespaceOfPrefix("w");
//find all the Elements in w:DocumentProperties Node.
IEnumerable<XElement> q = from ele in ex.Elements(xn + "DocumentProperties")
select ele;
foreach (XElement x in q.Elements())
{ //find the Title Node
if (x.Name == "Title") { //set value to Title node
x.Value = "hello";
}
}
ex.Save(Server.MapPath("test.xml"));
}
Member
46 Points
459 Posts
Issue with replacing xml nodes
Jul 09, 2014 01:36 PM|Chithra_Iyer|LINK
I want to replace the entire token node from the below xml
I tried using XMldocument and Xdoc for this but not getting the entire node.Also i want to replace the entire Token node with a different Token node from another XML.
Please could you help me out here
None
0 Points
4 Posts
Re: Issue with replacing xml nodes
Jul 10, 2014 02:39 AM|Abidali440|LINK
You can use RegularExpression to find and replace entire node from the xml. Below is the example you can use to do same.
Thanks,
Abidali
regex
All-Star
16806 Points
2777 Posts
Re: Issue with replacing xml nodes
Jul 10, 2014 04:51 AM|Kevin Shen - MSFT|LINK
Hi Chithra_lyer,
First ,I add your xml file to my project ,it hint me that the xml is not valid.
Second, you can use linq to xml to get the entire node. and replace your Token node with other's value.
I write a sample for you:
here is my test.xml file:
Below you can find DocumentPropertites , and replace the value in the subnode in it.
for example ,set the Title value from "title" to "hello".
More details ,please refer to the link below:
http://msdn.microsoft.com/en-US/us-en/library/bb387098.aspx
Best Regards,
Kevin Shen.