Click here to Skip to main content
15,797,984 members
Please Sign up or sign in to vote.
2.00/5 (3 votes)
See more:

sample code is,

<Root xmlns:xsi="" xmlns:xsd="" Version="V1.0"></Root>

In this I need to remove xsd namespace.


<Root xmlns:xsi=""  Version="V1.0"></Root>

I am using serialization.

How to achieve this in c# ?


What I have tried:

 XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
//                ns.Add("xsd", "");
//                ns.Add("", "");

If I give prefix as empty , xsd and xsi both namespaces are gone.
if I give prefix as xsd, it throws exception
Updated 12-Dec-17 23:11pm
F-ES Sitecore 13-Dec-17 4:23am    
Just do a string.Replace on the raw xml and replace the text you want gone with "". However I suspect you are trying to solve the wrong problem and trying to get rid of that text rather than getting your code to work with it.
vksvpp 13-Dec-17 4:49am    
this is required while generating xml

1 solution

You can simple split the XML string by blank and remove the part with "xmlns:xsd":

string strXml = "<Root xmlns:xsi='' xmlns:xsd='' Version='V1.0'></Root>";
string[] ar = strXml.Split(' ');
string strResult = string.Empty;
foreach (string str in ar)
   if (!str.Contains("xmlns:xsd"))
       strResult  += str + " ";
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900