locked
Correct way to have XML to C# class RRS feed

  • Question

  • User-284642143 posted

    For a learning curve and to ensure i'm not introducing bad habits, Im trying to find the correct procedure to get an XSD into a C# class. If you have an XSD which contains references to other XSDs and generate C# classes would you expect to change the automated class if required? I'm asking this to determine if this is ok and if not is this an indication the class has not been created correctly.

    Currently when i use the XSD supplied and an online service to generate the XML, the C# classes generated are slightly incorrect (i receive an error that the XML received is incorrect (1, 40)), so i added the odd property along with the Element it requires and all is working again.

    I tried XSD.exe but that created one huge class and i wasnt sure which the base class was or even if i took a guess i wasnt entirely sure if i was to call one URL (to get the data) then iterate through the data returned or use this data to make another call to another URL (i.e. first call is a list of customers and the second call would then be to pass in the ID of the record to get that record's detail).

    I have read some of the links posted in the past but just want to make sure im on the right track. Thanks in advance

    Monday, September 23, 2019 3:11 PM

All replies

  • User288213138 posted

    Hi EssCee,

    would you expect to change the automated class if required? I'm asking this to determine if this is ok and if not is this an indication the class has not been created correctly

    You are on the right track.

    But i suggest you don't modify the generated class, because It may causing program issue if you update the XSD file.

    Best regards,

    Sam

    Wednesday, September 25, 2019 6:20 AM
  • User-284642143 posted

    Thanks with the XSD residing with a 3rd party i dont believe they would change it (if they did, i would assume they would have a new URL targeting the new changes rather than changing the old service which could introduce breaking changes). In which case if this scenario stands and if i have understood you, then this means its ok to change the class to meet the requirements as long as the XSD doesnt change?

    Monday, September 30, 2019 3:06 PM