Generate class from xml schema (.xsd)

Could someone help me with an advice on how to generate Xojo classes from xml schema (.xsd) files? Here is an example that is a resource the HL7 FHIR standard. They provide this xsd files for every resource in the standard for code generation purposes.

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://hl7.org/fhir" xmlns:xhtml="http://www.w3.org/1999/xhtml" targetNamespace="http://hl7.org/fhir" elementFormDefault="qualified" version="1.0"> <xs:include schemaLocation="fhir-base.xsd"/> <xs:element name="Medication" type="Medication"> <xs:annotation> <xs:documentation xml:lang="en">This resource is primarily used for the identification and definition of a medication for the purposes of prescribing, dispensing, and administering a medication as well as for making statements about medication use.</xs:documentation> </xs:annotation> </xs:element> <xs:complexType name="Medication"> <xs:annotation> <xs:documentation xml:lang="en">This resource is primarily used for the identification and definition of a medication for the purposes of prescribing, dispensing, and administering a medication as well as for making statements about medication use.</xs:documentation> <xs:documentation xml:lang="en">If the element is present, it must have either a @value, an @id, or extensions</xs:documentation> </xs:annotation> <xs:complexContent> <xs:extension base="DomainResource"> <xs:sequence> <xs:element name="identifier" minOccurs="0" maxOccurs="unbounded" type="Identifier"> <xs:annotation> <xs:documentation xml:lang="en">Business identifier for this medication.</xs:documentation> </xs:annotation> </xs:element> <xs:element name="code" minOccurs="0" maxOccurs="1" type="CodeableConcept"> <xs:annotation> <xs:documentation xml:lang="en">A code (or set of codes) that specify this medication, or a textual description if no code is available. Usage note: This could be a standard medication code such as a code from RxNorm, SNOMED CT, IDMP etc. It could also be a national or local formulary code, optionally with translations to other code systems.</xs:documentation> </xs:annotation> </xs:element> <xs:element name="status" minOccurs="0" maxOccurs="1" type="MedicationStatusCodes"> <xs:annotation> <xs:documentation xml:lang="en">A code to indicate if the medication is in active use.</xs:documentation> </xs:annotation> </xs:element> <xs:element name="manufacturer" minOccurs="0" maxOccurs="1" type="Reference"> <xs:annotation> <xs:documentation xml:lang="en">Describes the details of the manufacturer of the medication product. This is not intended to represent the distributor of a medication product.</xs:documentation> </xs:annotation> </xs:element> <xs:element name="form" minOccurs="0" maxOccurs="1" type="CodeableConcept"> <xs:annotation> <xs:documentation xml:lang="en">Describes the form of the item. Powder; tablets; capsule.</xs:documentation> </xs:annotation> </xs:element> <xs:element name="amount" minOccurs="0" maxOccurs="1" type="Ratio"> <xs:annotation> <xs:documentation xml:lang="en">Specific amount of the drug in the packaged product. For example, when specifying a product that has the same strength (For example, Insulin glargine 100 unit per mL solution for injection), this attribute provides additional clarification of the package amount (For example, 3 mL, 10mL, etc.).</xs:documentation> </xs:annotation> </xs:element> <xs:element name="ingredient" type="Medication.Ingredient" minOccurs="0" maxOccurs="unbounded"> <xs:annotation> <xs:documentation xml:lang="en">Identifies a particular constituent of interest in the product.</xs:documentation> </xs:annotation> </xs:element> <xs:element name="batch" type="Medication.Batch" minOccurs="0" maxOccurs="1"> <xs:annotation> <xs:documentation xml:lang="en">Information that only applies to packages (not products).</xs:documentation> </xs:annotation> </xs:element> </xs:sequence> </xs:extension> </xs:complexContent> </xs:complexType> <xs:complexType name="Medication.Ingredient"> <xs:annotation> <xs:documentation xml:lang="en">This resource is primarily used for the identification and definition of a medication for the purposes of prescribing, dispensing, and administering a medication as well as for making statements about medication use.</xs:documentation> </xs:annotation> <xs:complexContent> <xs:extension base="BackboneElement"> <xs:sequence> <xs:element name="itemCodeableConcept" type="CodeableConcept" minOccurs="0"> <xs:annotation> <xs:documentation xml:lang="en">The actual ingredient - either a substance (simple ingredient) or another medication of a medication. (choose any one of item*, but only one)</xs:documentation> </xs:annotation> </xs:element> <xs:element name="itemReference" type="Reference" minOccurs="0"> <xs:annotation> <xs:documentation xml:lang="en">The actual ingredient - either a substance (simple ingredient) or another medication of a medication. (choose any one of item*, but only one)</xs:documentation> </xs:annotation> </xs:element> <xs:element name="isActive" minOccurs="0" maxOccurs="1" type="boolean"> <xs:annotation> <xs:documentation xml:lang="en">Indication of whether this ingredient affects the therapeutic action of the drug.</xs:documentation> </xs:annotation> </xs:element> <xs:element name="strength" minOccurs="0" maxOccurs="1" type="Ratio"> <xs:annotation> <xs:documentation xml:lang="en">Specifies how many (or how much) of the items there are in this Medication. For example, 250 mg per tablet. This is expressed as a ratio where the numerator is 250mg and the denominator is 1 tablet.</xs:documentation> </xs:annotation> </xs:element> </xs:sequence> </xs:extension> </xs:complexContent> </xs:complexType> <xs:complexType name="Medication.Batch"> <xs:annotation> <xs:documentation xml:lang="en">This resource is primarily used for the identification and definition of a medication for the purposes of prescribing, dispensing, and administering a medication as well as for making statements about medication use.</xs:documentation> </xs:annotation> <xs:complexContent> <xs:extension base="BackboneElement"> <xs:sequence> <xs:element name="lotNumber" minOccurs="0" maxOccurs="1" type="string"> <xs:annotation> <xs:documentation xml:lang="en">The assigned lot number of a batch of the specified product.</xs:documentation> </xs:annotation> </xs:element> <xs:element name="expirationDate" minOccurs="0" maxOccurs="1" type="dateTime"> <xs:annotation> <xs:documentation xml:lang="en">When this specific batch of product will expire.</xs:documentation> </xs:annotation> </xs:element> </xs:sequence> </xs:extension> </xs:complexContent> </xs:complexType> <xs:simpleType name="MedicationStatusCodes-list"> <xs:restriction base="code-primitive"> <xs:enumeration value="active"> <xs:annotation> <xs:documentation xml:lang="en">Active</xs:documentation> </xs:annotation> </xs:enumeration> <xs:enumeration value="inactive"> <xs:annotation> <xs:documentation xml:lang="en">Inactive</xs:documentation> </xs:annotation> </xs:enumeration> <xs:enumeration value="entered-in-error"> <xs:annotation> <xs:documentation xml:lang="en">Entered in Error</xs:documentation> </xs:annotation> </xs:enumeration> </xs:restriction> </xs:simpleType> <xs:complexType name="MedicationStatusCodes"> <xs:annotation> <xs:documentation xml:lang="en">A coded concept defining if the medication is in active use.</xs:documentation> <xs:documentation xml:lang="en">If the element is present, it must have either a @value, an @id, or extensions</xs:documentation> </xs:annotation> <xs:complexContent> <xs:extension base="Element"> <xs:attribute name="value" type="MedicationStatusCodes-list" use="optional"/> </xs:extension> </xs:complexContent> </xs:complexType> </xs:schema>

There is not an “automatic” way to create a class, you have to understand the XSD, and manyally create your classes with the XMLDocument

XMLDocument

Thanks for your answer. I was looking if there is an automatic tool for this. In other languages it is my understanding that this could be done automatically with tools like “xsd2code” in .net

Xojo it is very limited in tools like that. Even the XML is prety basic and outdated. Basic functionality like XSLT, it is really slow and only support XSLT 1.0 (From 1999 LOL)

So, if you are going to work extensively with XML, make sure that xojo is the right tool, you will need to do many things manually or even to buy plugins.

Until someone wrote xsd2code it wasn’t “automatic” for .Net (ie/ not part of .Net). If someone writes xsd2xojo it will be similarly “automatic”.

it’s doable.

I wrote something for a much more complex xsd (+100 classes)
but it was for an internal work so I can’t publish it (you had to finalise some edge cases by hand, since the source was over engineered and a lot of classes were the same, for the same purpose, probably it was the result of an automatic analyser )

I agree with Antonio, I also did something like that and can’t publish for the same reason.