Using XSD to create a XML file RRS feed

  • Question

  • I have tried to generate a xml file by creating xsd with the class hierarchy as needed for the xml.

    But the xml file generated contains namespace and other information as mentioned below


    How to get ride of the namespace in the xml file?

    I need the xml sample as mentioned below. 

    <?xml version="1.0" encoding="utf-8"?>

    Suggest any better ways to do this. I used xsd as i have large number of class in my xml file.

    Tuesday, October 16, 2018 8:34 AM

All replies

  • Hello, 

    How to get ride of the namespace in the xml file?

    You need to give to Serializer a Namespaces collection with single empty-empty entry. 


    The file you expecting you can generate using XSLT applied to your XSD.

    Sincerely, Highly skilled coding monkey.

    Tuesday, October 16, 2018 8:51 AM
  • Hi Manoj 1503,

    Here is the document about How to: Create an XML document based on an XSD schema for your reference.

    In addition, you could also generate related XSD schema via xml file by using XSD.exe, which could use command in visual studio command prompt. 

    xsd c:\xmlpath\Test.xml /outputdir:C:\outputpapth

    Best regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Wednesday, October 17, 2018 6:20 AM
  • Thank you.

    >The file you expecting you can generate using XSLT applied to your XSD.

    could you share any sample for using XSLT?

    I have used to create xml with namespace as empty, still i get all the xsd declaration in my file.

    using (var stream = new FileStream(path, FileMode.Create))
                    XmlSerializerNamespaces ns = new XmlSerializerNamespaces();

                    XmlSerializer ser = new XmlSerializer(typeof(Emp.EMPLOYEESDataTable));
                    XmlTextWriter xmlWriter = new XmlTextWriter(stream, Encoding.UTF8);
                    xmlWriter.Formatting = Formatting.Indented;
                    ser.Serialize(xmlWriter, dataObj, ns);

    By using above code i created my xml file.

    Wednesday, October 17, 2018 8:23 AM
  • If I understand you correcty: Remove all namespace declarations in the generated classes.
    Wednesday, October 17, 2018 8:33 AM
  • This was too long ago to remember all details, but try this:

    XmlSerializerNamespaces ns = new XmlSerializerNamespaces(
                             new[] { XmlQualifiedName.Empty });


    XSLT solution - possible, but implementation will take too much of my time - I need to do my job. 

    Sincerely, Highly skilled coding monkey.

    Wednesday, October 17, 2018 10:28 AM