views:

315

answers:

3

I know that you cannot fully describe the XML that the TClientDataSet with an XSD schema, as the ROW elements have attributes that have names that vary with the contents.

However, the METADATA section of such an XML should be.

So: is there anyone having a (partial) XSD that describes the METADATA portion of the XML that can be saved with Delphi TClientDataSets?

Regards,

Jeroen Pluimers

PS: Thanks for the pointers to XML->XSD conversion tools/sites; I should have written that I did that myself as well, but that generating that XSD in a proper way (i.e. one that covers all possibilities) will need input XML that cover all possibilities (like roundtrip, rowstate, etc). I'll try to come up with a decent XSD that way and post it here.

+6  A: 

Well I couldn't find one either, so I used this website to generate this schema based on a ClientDataSet XML file.

<?xml version="1.0" encoding="UTF-8" ?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
  <xs:element name="DATAPACKET">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="METADATA" />
        <xs:element ref="ROWDATA" />
      </xs:sequence>
      <xs:attribute name="Version" type="xs:NMTOKEN" use="required" />
    </xs:complexType>
  </xs:element>

  <xs:element name="FIELD">
    <xs:complexType>
      <xs:attribute name="fieldtype" type="xs:NMTOKEN" use="required" />
      <xs:attribute name="WIDTH" type="xs:NMTOKEN" use="optional" />
      <xs:attribute name="attrname" type="xs:NMTOKEN" use="required" />
      <xs:attribute name="required" type="xs:NMTOKEN" use="optional" />
    </xs:complexType>
  </xs:element>

  <xs:element name="FIELDS">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="FIELD" maxOccurs="unbounded" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="METADATA">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="FIELDS" />
        <xs:element ref="PARAMS" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="PARAMS">
    <xs:complexType>
      <xs:attribute name="CHANGE_LOG" type="xs:string" use="required" />
    </xs:complexType>
  </xs:element>

  <xs:element name="ROW">
    <xs:complexType>
    </xs:complexType>
  </xs:element>

  <xs:element name="ROWDATA">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="ROW" maxOccurs="unbounded" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>

</xs:schema>
_J_
+2  A: 

The XSD below seems to work reasonably so far; if you have TClientDataSet XML that does not validat with this, please email me your XML (Google me or pm me for my mail address).

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
    <xs:element name="DATAPACKET">
     <xs:complexType>
      <xs:sequence>
       <xs:element ref="METADATA"/>
       <xs:element ref="ROWDATA"/>
      </xs:sequence>
      <xs:attribute name="Version" type="xs:NMTOKEN" use="required"/>
     </xs:complexType>
    </xs:element>
    <xs:element name="FIELD">
     <xs:complexType>
      <xs:sequence>
       <xs:element ref="PARAM"/>
      </xs:sequence>
      <xs:attribute name="fieldtype" use="required">
       <xs:simpleType>
        <xs:restriction base="xs:NMTOKEN">
         <xs:enumeration value="fixed"/>
         <xs:enumeration value="i2"/>
         <xs:enumeration value="i4"/>
         <xs:enumeration value="string"/>
         <xs:enumeration value="bin.hex"/>
        </xs:restriction>
       </xs:simpleType>
      </xs:attribute>
      <xs:attribute name="SUBTYPE" use="optional">
       <!-- required for fieldtype="bin.hex" -->
       <xs:simpleType>
        <xs:restriction base="xs:NMTOKEN">
         <xs:enumeration value="Binary"/>
        </xs:restriction>
       </xs:simpleType>
      </xs:attribute>
      <xs:attribute name="WIDTH" use="optional" type="xs:positiveInteger"/>
      <xs:attribute name="attrname" type="xs:ID" use="required"/>
     </xs:complexType>
    </xs:element>
    <xs:element name="FIELDS">
     <xs:complexType>
      <xs:sequence>
   <xs:element ref="FIELD" maxOccurs="unbounded"/>
      </xs:sequence>
     </xs:complexType>
    </xs:element>
    <xs:element name="METADATA">
     <xs:complexType>
      <xs:sequence>
       <xs:element ref="FIELDS"/>
       <xs:element ref="PARAMS"/>
      </xs:sequence>
     </xs:complexType>
    </xs:element>
    <xs:element name="PARAM">
     <xs:complexType>
      <xs:attribute name="Name" type="xs:NMTOKEN" use="required" fixed="ORIGIN"/>
      <xs:attribute name="Value" type="xs:ID" use="required"/>
      <xs:attribute name="Roundtrip" type="xs:NMTOKEN" use="required" fixed="True"/>
     </xs:complexType>
    </xs:element>
    <xs:element name="PARAMS">
     <xs:complexType>
      <xs:attribute name="CHANGE_LOG" type="xs:string" use="optional"/>
     </xs:complexType>
    </xs:element>
    <xs:element name="ROW">
     <xs:complexType>
      <xs:attribute name="RowState" type="xs:NMTOKEN" use="optional"/>
      <xs:anyAttribute namespace="##any" processContents="lax"/>
 </xs:complexType>
    </xs:element>
    <xs:element name="ROWDATA">
     <xs:complexType>
      <xs:sequence>
       <xs:element ref="ROW" maxOccurs="unbounded"/>
      </xs:sequence>
     </xs:complexType>
    </xs:element>
</xs:schema>

Regards,

Jeroen Pluimers

Jeroen Pluimers
+1  A: 

Hi,

I am a total newbie in Delphi, but had to deal with parsing a TClientDataSet in XML format. I also needed a list of all the possible values for the field type. Did some digging into the Delphi source and came up with this list.

If you want to include the field types in the schema then you should include all the types listed here:

<xs:enumeration value="string" />
<xs:enumeration value="id" />
<xs:enumeration value="idref" />
<xs:enumeration value="idrefs" />
<xs:enumeration value="entity" />
<xs:enumeration value="entities" />
<xs:enumeration value="nmtoken" />
<xs:enumeration value="nmtokens" />
<xs:enumeration value="number" />
<xs:enumeration value="int" />
<xs:enumeration value="enumeration" />
<xs:enumeration value="notation" />
<xs:enumeration value="fixed" />
<xs:enumeration value="boolean" />
<xs:enumeration value="dateTime" />
<xs:enumeration value="dateTime.tz" />
<xs:enumeration value="date" />
<xs:enumeration value="time" />
<xs:enumeration value="time.tz" />
<xs:enumeration value="i1" />
<xs:enumeration value="byte" />
<xs:enumeration value="i2" />
<xs:enumeration value="i4" />
<xs:enumeration value="i8" />
<xs:enumeration value="ui1" />
<xs:enumeration value="ui2" />
<xs:enumeration value="ui4" />
<xs:enumeration value="ui8" />
<xs:enumeration value="r4" />
<xs:enumeration value="r8" />
<xs:enumeration value="float" />
<xs:enumeration value="char" />
<xs:enumeration value="uuid" />
<xs:enumeration value="bin.hex" />
<xs:enumeration value="bin.base64" />

Thanks for a doing a nice job of defining this schema. This helps a lot.

Best wishes,
Ats Jenk

ats
Thanks! The project I needed it for has been completed with partial validation, but when I need completer validation, I'll take your addition in to account.
Jeroen Pluimers