using System;
using System.Xml;
public class Program
{
public static void Main()
{
var xml = @"<ENVELOPE>
<HEADER>
<VERSION>1</VERSION>
<STATUS>1</STATUS>
</HEADER>
<BODY>
<DATA>
<MESSAGE>
<VOUCHER >
<GUID>9740ced1-ae14-4acc-be43-d3e250e6bf71-00000005</GUID>
<REMOTEALTGUID>9740ced1-ae14-4acc-be43-d3e250e6bf71</REMOTEALTGUID>
<UDF:VATDEALERNATURE.LIST DESC="`VATDealerNature`" ISLIST="YES" TYPE="String" INDEX="10031">
<UDF:VATDEALERNATURE DESC="`VATDealerNature`">Regular</UDF:VATDEALERNATURE>
</UDF:VATDEALERNATURE.LIST>
</VOUCHER>
</MESSAGE>
</DATA>
</BODY>
</ENVELOPE>";
var document = new XmlDocument();
document.LoadXml(xml);
XmlNodeList nodes = doc.GetElementsByTagName("UDF:VATDEALERNATURE.LIST");
for (int i = 0; i < nodes.Count; i++)
{
Console.WriteLine(nodes[i].InnerXml);
nodes[i].ParentNode.RemoveChild(nodes[i]);
}
}
}
XmlNamespaceManager xmlnsManager=new System.Xml.XmlNamespaceManager(doc.NameTable);
xmlnsManager.AddNamespace("UDF","");
XmlNodeList nodes = doc.GetElementsByTagName("UDF:*");
foreach (XmlNode xNode in nodes)
{
xNode.ParentNode.RemoveChild(xNode);
}
/* for (int i = 0; i < nodes.Count; i++)
{
Console.WriteLine(nodes[i].InnerXml);
nodes.ParentNode.RemoveChild(nodes[i]);
}*/
if (doc.DocumentElement.Name== "UDF_VATDEALERNATURE.LIST")
{
string tempxmlstring = doc.DocumentElement.InnerXml;
doc.LoadXml(tempxmlstring);
}
<ENVELOPE>
<HEADER>
<VERSION>1</VERSION>
<STATUS>1</STATUS>
</HEADER>
<BODY>
<DATA>
<MESSAGE>
<VOUCHER >
<GUID>9740ced1-ae14-4acc-be43-d3e250e6bf71-00000005</GUID>
<REMOTEALTGUID>9740ced1-ae14-4acc-be43-d3e250e6bf71</REMOTEALTGUID>
</VOUCHER>
</MESSAGE>
</DATA>
</BODY>
</ENVELOPE>
<UDF:VATDEALERNATURE.LIST DESC="`VATDealerNature`" ISLIST="YES" TYPE="String" INDEX="10031">
<UDF:VATDEALERNATURE DESC="`VATDealerNature`">Regular</UDF:VATDEALERNATURE>
</UDF:VATDEALERNATURE.LIST>
<ENVELOPE>
with <ENVELOPE xmlns:UDF="null">
to declare the UDF namespace prefix. After that the xml is valid and can be treated as such. Then you can for example use xpath lookup for //UDF:*
nodes and remove each from the document.