Removing q1 from the serialized XML using XMLSerializer RRS feed

  • Question

  •  I am using XMLSerializer to serialie my object to xml and I was trying to remove the default xmlns:xsi and xmlns:xsd that gets generated.

     <MyXml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="MyNameSpace">

    I see that it can be removed by setting your own namespace
    XMLSerializerNameSpace ns = new XMLSerializerNameSpace()

    This removes the xmlns:xsi and xmlns:xsd however the serialized xml has a q1 tag which I am not sure how to remove.

     <q1:MyXml xmlns:q1="MyNameSpace">

    The best I could do was to generate something with a prefix -
    by doing something like
     <MyXml xmlns:ns="MyNameSpace">

    Any ideas on how to either remove the q1 tag or the prefix?

    Wednesday, October 22, 2008 6:05 AM


  • Why do you want it removed? If your XML is in a namespace (and it should be, in almost all cases), then the namespace needs to be declared somewhere.

    Try specifying ns.Add("", "MyNameSpace");

    John Saunders | Use File->New Project to create Web Service Projects
    Wednesday, October 22, 2008 7:34 AM