Clearing Only inner text and not the childnodes
I have an xml as below
< Image>ImageValue1
<Type>png</Type>
<Value>ImageValue1</ Value>
</ Image>
Here ImageValue1 is present in two pla开发者_开发技巧ces.I want to remove innerText for Image node which is the parent.For which I am using the below code
XmlNode customImageNode = imagedoc.SelectSingleNode("//Image");
customImageNode.InnerText = string.empty;
But this is clearing the child nodes as well.Please let me know how to clear this test off .Looking for a generic solution.
I believe what you need to do is select just the text node of the Image
node. You do this like this:
XmlNode customImageNodeTextNode = imageDoc.SelectSingleNode("//Image/text()");
customImageNodeTextNode.InnerText = string.Empty;
I just tested the above code and it worked for me. Good luck!
try doing:
customImageNode.Value= string.empty;
update:
sorry for the mistake. It's supposed to be like so: customImageNode.RemoveChild(customImageNode.FirstChild);
, since the inner text of the node is it's first child in this case. I've checked it and it works.
精彩评论