Search code examples
c#xmlxml-serializationxsd

How to convert this XML Definition into a C# Class


Is there a 'standard' way to convert something like this into a set of C# classes?

<!DOCTYPE MESSAGES [
<!ELEMENT MESSAGES (MSG*)>
<!ELEMENT MSG (TO+,BODY,MSG_ID,BILLING)>
<!ATTLIST MSG TYPE (CONTENT|LOGO|RINGTONE|PICTURE|OTAPUSH|BINFWD|LONGSMS|2DCODE) #REQUIRED>
<!ELEMENT TO (#PCDATA)>
<!ATTLIST TO PROVID (1|2|3|5|6|7) #IMPLIED >
<!ATTLIST TO TYPE (NPM|EMS) #IMPLIED>
<!ELEMENT BODY (#PCDATA)>
<!ELEMENT MSG_ID (#PCDATA)>
<!ELEMENT BILLING (#PCDATA)>
<!ELEMENT DELIVERY (#PCDATA)>
<!ELEMENT EXPDATE (#PCDATA)>
]>

I have some more information but would greatly appreciate a way to transform the ELEMENT and ATTLIST into C#.


Solution

  • If you convert your DTD to an XSD schema using this w3c tool, you can use xsd.exe or XML Sample Code Generator to create the classes.