none
xsd.exe generated classes result in XML error on (0,0) RRS feed

  • Question

  • When I start from an XSD then undertake two steps:

    1. generate sample XML from XSD

    2. copy/paste special the XML as Classes (via VS menu)

    I get nice generated classes. Next step is to

    3. convert the generated XML into the classes via deserializer.

    Unfortunately that won't work. The result is an error on the deserializer 'There is an error in XML document (0,0)'. The inner exception tells me that the "Root element is missing".

    The XSD validates correctly, the XML validates correctly, so what is wrong here?

    Here's my deserializer:

                MyStream.Position = 0
                Dim _XMLSerializer As New XmlSerializer(GetType(T))
                Dim MyObject As T = CType(_XMLSerializer.Deserialize(MyStream), T)
                Return MyObject

    The XML file is (of course!) first read into the MyStream MemoryStream. I can see in the properties of the _XMLSerializer that the XML data is there. The error arises  where the Deserializer casts the content into a "T" object.

    Is XSD.exe inconsistent in itself?? What is the problem here?

     Oh, and this is the XSD I started off with. It is provided from elsewhere, and the definition or structure is out of my hands.


    "Every misfortune is a new challenge"




    • Edited by WayPoint7 Friday, July 31, 2015 1:01 PM typographic enhancements
    Friday, July 31, 2015 12:02 PM

All replies

  • Can you post a sample of the XML and a complete repro?

    David


    David http://blogs.msdn.com/b/dbrowne/

    Friday, July 31, 2015 1:59 PM
  • Sure David!

    Thanks for getting back to me. It is quite simple in fact, you can also completely reproduce it starting from the xsd that is attached to the link in my first post, and I attach that again for your convenience here.

    To keep this post a bit better readable, I will provide links to the files that are related to this issue.

    This is the example XML that is generated from the XSD. That's the result of step 1 in my question.

    And these are the classes definitions that result from the Paste Special menu option, step 2.

    The generic T object that I insert into the Deserializer routine is of type "AW33Bericht", so I would expect that to be the class object to be filled with the XML data after the deserialization process.

    NB! There is a link to this basisschema.xsd file in the first XSD, but when I include that into the generation process (command: XSD aw33.xsd basisschema.xsd /c /l:VB) a more complex class structure is generated, but it yields the same result.

    If you need more information, please get back to me.


    "Every misfortune is a new challenge"

    Friday, July 31, 2015 4:05 PM