Using XML Enumerations Using the Delphi XML Data Binding Wizard

I have an XML schema that uses enumerations, but when I look at the generated XML object in Delphi, the enumeration restriction has been dropped. Is there a way to get Delphi to generate an enumeration and build it in an object?

XSD Snippet:

<xs:simpleType name="enumType" final="restriction"> <xs:restriction base="xs:NMTOKEN"> <xs:enumeration value="Each"/> <xs:enumeration value="Units"/> <xs:enumeration value="Area"/> <xs:enumeration value="Payroll"/> <xs:enumeration value="Sales"/> <xs:enumeration value="TotalCost"/> <xs:enumeration value="Other"/> </xs:restriction> </xs:simpleType> 

What I expect to see in Delphi is a field that takes an enumeration, which then converts to it, matching a string when generating XML, but this field is a regular string.

+6
xml delphi xsd
source share
2 answers

What you can do is create your own enumerated type with the same string constants as the names, and use the TypInfo module using the GetEnumValue and GetEnumString functions. This allows you to prefix names with a few lowercase letters, for example, in another Delphi code:

 Value := TMyEnum( GetEnumValue( typeinfo( TMyEnum ), Prefix + AString ) ) 
+5
source share

The XML Data Binding Wizard cannot do what you want.

The reason is because XSD enumerations are not compatible with delphi identifiers, because they are:

  • may contain characters incompatible with the Delphi identifier
  • case sensitive

Basically, XSD enums are just strings with limited values.

See listing specifications and an example .

Both are clearly incompatible with Delphi enum types.

Edit: 20100125 - Delphi attributes

Here's an interesting question about how far you could go with the new RTTI attribute and support in Delphi 2010.

- Jeroen

+2
source share

All Articles