任何有部分XSD描述Delphi TClientDataSet XML文件的METADATA部分的人? [英] Anyone that has a partial XSD that describes the METADATA section of Delphi TClientDataSet XML files?

查看:278
本文介绍了任何有部分XSD描述Delphi TClientDataSet XML文件的METADATA部分的人?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道你不能完全描述具有XSD架构的TClientDataSet的XML,因为ROW元素的属性具有随内容变化的名称。



但是,这样一个XML的METADATA部分应该是。



那么有没有人有(部分)XSD描述可以保存的XML的METADATA部分使用Delphi TClientDataSets?



问候。



PS:



感谢您指向XML-> XSD转换工具/网站;我应该写道,我也是这样做的,但是以正确的方式(即覆盖所有可能性的方式)生成XSD将需要输入XML来覆盖所有可能性(如往返,行状态等)。
我会尝试提出一个体面的XSD,并在这里发布。

解决方案

编辑:

将XSD分成两部分,并通过在 Delphi XE 中使用这些文件使其更完整: dsconst.h dspickle.h dsxml.h

如果您有添加,请PM或评论。



下面的XSD文件似乎工作合理;如果您有TClientDataSet XML不能验证,请给我发送您的XML(Google我或在我的邮箱地址下面发表评论)。



首先将文件 CDS.xsd ,其中包括文件 CDS_METADATA_FIELDS_include.xsd 进一步。

它定义了基本TClientDataSet XML文档的结构: DATAPACKET ,包含 METADATA ROWDATA ,其中 METADATA 包含 FIELDS PARAMS ,以及 ROWDATA 包含 ROW 元素:

 code><?xml version =1.0encoding =UTF-8?> 
< xs:schema xmlns:xs =http://www.w3.org/2001/XMLSchema>
< xs:include schemaLocation =CDS_METADATA_FIELDS_include.xsd/>
<! - DATAPACKET / datapacket - >
< xs:element name =DATAPACKETtype =datapacket/>
< xs:complexType name =datapacket>
< xs:sequence>
< xs:element ref =METADATA/>
< xs:element ref =ROWDATA/>
< / xs:sequence>
< xs:attribute name =Versiontype =xs:NMTOKENuse =required/>
< / xs:complexType>
<! - METADATA / metadata - >
< xs:element name =METADATAtype =metadata/>
< xs:complexType name =metadata>
< xs:sequence>
< xs:元素ref =FIELDS/>
< xs:element ref =PARAMS/>
< / xs:sequence>
< / xs:complexType>
<! - PARAMS / params - >
< xs:element name =PARAMStype =params/>
< xs:complexType name =params>
< xs:attribute name =MD_FIELDLINKStype =xs:stringuse =optional/>
< xs:attribute name =DEFAULT_ORDERtype =xs:positiveInteger/>
< xs:attribute name =LCIDtype =xs:positiveInteger/>
< xs:attribute name =CHANGE_LOGtype =xs:stringuse =optional/>
< xs:attribute name =PRIMARY_KEYtype =xs:positiveIntegeruse =optional/>
< / xs:complexType>
<! - ROWDATA / rowdata - >
< xs:element name =ROWDATAtype =rowdata/>
< xs:complexType name =rowdata>
< xs:sequence>
< xs:element ref =ROWminOccurs =0maxOccurs =unbounded/>
< / xs:sequence>
< / xs:complexType>
<! - ROW / row - >
< xs:element name =ROWtype =row/>
< xs:complexType name =row>
< xs:sequence>
< xs:any namespace =## anyprocessContents =laxminOccurs =0maxOccurs =unbounded/>
< / xs:sequence>
< xs:attribute name =RowStatetype =xs:NMTOKENuse =optional/>
< xs:anyAttribute namespace =## anyprocessContents =lax/>
< / xs:complexType>
< / xs:schema>

请注意, ROW 元素非常松散地键入,因为它们将包含动态定义的属性名称。



然后文件 CDS_METADATA_FIELDS_include.xsd 其中包含底层元数据由 FIELDS PARAMS 元素使用的元数据。

尚未完全完成,因为我还没有找到包含下面评论中提到的关键字的CDS XML文件。

 <?xml version =1.0 encoding =UTF-8?> 
<! - 包含CDS使用的METADATA FIELDS的部分 - >
< xs:schema xmlns:xs =http://www.w3.org/2001/XMLSchema>
<! - FIELDS / fields - >
< xs:element name =FIELDStype =fields/>
< xs:complexType name =fields>
< xs:sequence>
< xs:element ref =FIELDmaxOccurs =unbounded/>
< / xs:sequence>
< / xs:complexType>
<! - FIELD / field - >
< xs:element name =FIELDtype =field/>
< xs:complexType name =field>
< xs:sequence>
< xs:element ref =PARAMminOccurs =0/>
<! - FIELDS用于嵌套数据集 - >
< xs:element ref =FIELDSminOccurs =0maxOccurs =unbounded/>
<! - PARAMS用于嵌套数据集 - >
< xs:element name =PARAMStype =fieldParamsminOccurs =0maxOccurs =unbounded/>
< / xs:sequence>当DBMS允许在字段名称中使用非标识符字符(如空格)时,会使用
<! - fieldname - >
< xs:attribute name =fieldnameuse =optionaltype =xs:string/>
< xs:attribute name =fieldtypeuse =requiredtype =FIELDTYPE/>
< xs:attribute name =SUBTYPEuse =optionaltype =subtype/>
<! - DECIMALS是为BCD - >
< xs:attribute name =DECIMALStype =xs:positiveIntegeruse =optional/>
<! - WIDTH用于字符,BCD,字节和Unicode - >
< xs:attribute name =WIDTHtype =xs:positiveIntegeruse =optional/>
< xs:attribute name =attrnametype =xs:Nameuse =required/>
<! - 需要并入这些;可能作为FIELD的属性:
#define szUNIQUE_KEYUNIQUE_KEY
#define szSERVER_COLSERVER_COL
#define szCONSTRAINTS约束
#define szDATASET_CONTEXTDATASET_CONTEXT
#define szDATASET_DELTADATASET_DELTA
#define szREADONLYREADONLY
#define szBDEDOMXBDEDOMAIN_X
#define szBDERECXBDERECORD_X
#define szBDEDEFXBDEDEFAULT_X
#define szAUTOINCVALUEAUTOINCVALUE
#define szELEMENTSELEMENTS
#define szTABLENAMETABLENAME
#define szTYPENAMETYPENAME
#define szUPDATEMODEUPDATEMODE
#define szMD_SEMANTICSMD_SEMANTICS
#define szCALCULATEDCALCULATED
#define szFIELDNAMEFIELDNAME
- >
< / xs:complexType>
<! - fieldParams - >
< xs:complexType name =fieldParams>
< xs:attribute name =DEFAULT_ORDERtype =xs:positiveInteger/>
< xs:attribute name =PRIMARY_KEYtype =xs:positiveInteger/>
< xs:attribute name =LCIDtype =xs:positiveInteger/>
< / xs:complexType>
<! - FIELDTYPE - >
< xs:simpleType name =FIELDTYPE>
< xs:restriction base =xs:Name>
<! - 在现实生活中观察CDS XML: - >
< xs:枚举值=byte/>
<! - 从Delphi XE文件dsxml.h: - >
< xs:枚举值=i1/>
< xs:枚举值=i2/>
< xs:枚举值=i4/>
< xs:枚举值=i8/>
< xs:枚举值=ui1/>
< xs:枚举值=ui2/>
< xs:枚举值=ui4/>
< xs:枚举值=ui8/>
< xs:枚举值=r4/>
< xs:枚举值=r8/>
< xs:枚举值=r10/>
<! - szXMLFloat / szXMLNumber< xs:枚举值=r8/> - >
< xs:枚举值=固定/>
< xs:枚举值=fixedFMT/>
< xs:枚举值=boolean/>
< xs:枚举值=date/>
< xs:枚举值=dateTime/>
< xs:枚举值=时间/>
< xs:枚举值=array/>
< xs:枚举值=struct/>
< xs:枚举值=嵌套/>
< xs:枚举值=string.uni/>
< xs:枚举值=string/>
< xs:枚举值=bin.hex/>
< xs:枚举值=IntArray/>
< xs:枚举值=UIntArray/>
< xs:枚举值=SQLdateTime/>
< xs:枚举值=SQLdateTimeOffset/>
< / xs:restrict>
< / xs:simpleType>
<! - subtype - >
< xs:simpleType name =subtype>
< xs:restriction base =xs:Name>
< xs:枚举值=文本/>
< xs:枚举值=二进制/>
< xs:枚举值=格式化/>
< xs:枚举值=Ole/>
< xs:枚举值=Graphics/>
< xs:枚举值=dBASEOle/>
< xs:枚举值=TypedBinary/>
< xs:枚举值=金钱/>
< xs:枚举值=Autoinc/>
< xs:枚举值=AccessOle/>
< xs:枚举值=HMemo/>
< xs:枚举值=HBinary/>
< xs:枚举值=ADTNestedTable/>
< xs:枚举值=FixedChar/>
< xs:枚举值=参考/>
< xs:枚举值=BFile/>
< xs:枚举值=ADTDate/>
< xs:枚举值=Guid/>
< xs:枚举值=WideText/>
<! - fieldtype =bin.hex - >需要二进制
<! - 当字段为CHAR(但不是NCHAR)时,fieldtype =string需要FixedChar - >
<! - 当字段为GUID时,fieldtype =string需要Guid - >
<! - 当底层字段为TEXT或NTEXT(memo?)时,fieldtype =bin.hex需要文本 - >
<! - 当底层字段为CURRENCY时,fieldtype =float需要资金 - >
< / xs:restriction>
< / xs:simpleType>
<! - PARAM / param - >
< xs:element name =PARAMtype =param/>
< xs:complexType name =param>
< xs:attribute name =Nametype =paramNameuse =required/>
<! - 两种形式的价值是可能的; xs:名称用于ORIGIN; xs:postiveInteger是用于PROVFLAGS(与Type一起使用)
< xs:attribute name =Valuetype =xs:Nameuse =required/>
< xs:attribute name =Valuetype =xs:postiveIntegeruse =required/>
- >
< xs:attribute name =Valuetype =xs:stringuse =required/>
< xs:attribute name =Typetype =FIELDTYPEuse =optional/>
< xs:attribute name =Roundtriptype =xs:Nameuse =requiredfixed =True/>
< / xs:complexType>
<! - paramName - >
< xs:simpleType name =paramName>
< xs:restriction base =xs:Name>
< xs:枚举值=ORIGIN/>
< xs:枚举值=PROVFLAGS/>
< / xs:restriction>
< / xs:simpleType>
< / xs:schema>

问候。


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.

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.

解决方案

Edit:
Split the XSD in two parts, and made it more complete by using these files in Delphi XE: dsconst.h, dspickle.h, dsxml.h.
Please PM or comment if you have additions.

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

First the file CDS.xsd, which includes the file CDS_METADATA_FIELDS_include.xsd further on.
It defines the basic structure of a TClientDataSet XML document: DATAPACKET, containing METADATA and ROWDATA, where METADATA contains FIELDS and PARAMS, and ROWDATA contains ROW elements:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:include schemaLocation="CDS_METADATA_FIELDS_include.xsd"/>
    <!-- DATAPACKET/datapacket -->
    <xs:element name="DATAPACKET" type="datapacket"/>
    <xs:complexType name="datapacket">
        <xs:sequence>
            <xs:element ref="METADATA"/>
            <xs:element ref="ROWDATA"/>
        </xs:sequence>
        <xs:attribute name="Version" type="xs:NMTOKEN" use="required"/>
    </xs:complexType>
    <!-- METADATA/metadata -->
    <xs:element name="METADATA" type="metadata"/>
    <xs:complexType name="metadata">
        <xs:sequence>
            <xs:element ref="FIELDS"/>
            <xs:element ref="PARAMS"/>
        </xs:sequence>
    </xs:complexType>
    <!-- PARAMS/params -->
    <xs:element name="PARAMS" type="params"/>
    <xs:complexType name="params">
        <xs:attribute name="MD_FIELDLINKS" type="xs:string" use="optional"/>
        <xs:attribute name="DEFAULT_ORDER" type="xs:positiveInteger"/>
        <xs:attribute name="LCID" type="xs:positiveInteger"/>
        <xs:attribute name="CHANGE_LOG" type="xs:string" use="optional"/>
        <xs:attribute name="PRIMARY_KEY" type="xs:positiveInteger" use="optional"/>
    </xs:complexType>
    <!-- ROWDATA/rowdata -->
    <xs:element name="ROWDATA" type="rowdata"/>
    <xs:complexType name="rowdata">
        <xs:sequence>
            <xs:element ref="ROW" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>
    <!-- ROW/row -->
    <xs:element name="ROW" type="row"/>
    <xs:complexType name="row">
        <xs:sequence>
            <xs:any namespace="##any" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:attribute name="RowState" type="xs:NMTOKEN" use="optional"/>
        <xs:anyAttribute namespace="##any" processContents="lax"/>
    </xs:complexType>
</xs:schema>

Note that ROW elements are very loosely typed, as they will contain attribute names that are dynamically defined.

Then the file CDS_METADATA_FIELDS_include.xsd which contains the underlying meta data used by the FIELDS and PARAMS elements.
It is not yet fully complete, as I haven't found CDS XML files containing the keywords mentioned in the comments below.

<?xml version="1.0" encoding="UTF-8"?>
<!-- include portion of the METADATA FIELDS that CDS uses -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <!-- FIELDS/fields -->
  <xs:element name="FIELDS" type="fields"/>
  <xs:complexType name="fields">
    <xs:sequence>
      <xs:element ref="FIELD" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>
  <!-- FIELD/field -->
  <xs:element name="FIELD" type="field"/>
  <xs:complexType name="field">
    <xs:sequence>
      <xs:element ref="PARAM" minOccurs="0"/>
      <!-- FIELDS is for nested datasets -->
      <xs:element ref="FIELDS" minOccurs="0" maxOccurs="unbounded"/>
      <!-- PARAMS is for nested datasets -->
      <xs:element name="PARAMS" type="fieldParams" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
    <!-- fieldname is used when the DBMS allows for non-identifier characters (like spaces) in fieldnames -->
    <xs:attribute name="fieldname" use="optional" type="xs:string"/>
    <xs:attribute name="fieldtype" use="required" type="FIELDTYPE"/>
    <xs:attribute name="SUBTYPE" use="optional" type="subtype"/>
    <!-- DECIMALS is for BCD -->
    <xs:attribute name="DECIMALS" type="xs:positiveInteger" use="optional"/>
    <!-- WIDTH is for Character, BCD, Bytes and Unicode -->
    <xs:attribute name="WIDTH" type="xs:positiveInteger" use="optional"/>
    <xs:attribute name="attrname" type="xs:Name" use="required"/>
<!-- need to incorporate these; probably as attributes as FIELD :
#define szUNIQUE_KEY          "UNIQUE_KEY"
#define szSERVER_COL          "SERVER_COL"
#define szCONSTRAINTS         "CONSTRAINTS"
#define szDATASET_CONTEXT     "DATASET_CONTEXT"
#define szDATASET_DELTA       "DATASET_DELTA"
#define szREADONLY            "READONLY"
#define szBDEDOMX             "BDEDOMAIN_X"
#define szBDERECX             "BDERECORD_X"
#define szBDEDEFX             "BDEDEFAULT_X"
#define szAUTOINCVALUE        "AUTOINCVALUE"
#define szELEMENTS            "ELEMENTS"
#define szTABLENAME           "TABLENAME"
#define szTYPENAME            "TYPENAME"
#define szUPDATEMODE          "UPDATEMODE"
#define szMD_SEMANTICS        "MD_SEMANTICS"
#define szCALCULATED          "CALCULATED"
#define szFIELDNAME          "FIELDNAME"
-->
  </xs:complexType>
  <!-- fieldParams -->
  <xs:complexType name="fieldParams">
    <xs:attribute name="DEFAULT_ORDER" type="xs:positiveInteger"/>
    <xs:attribute name="PRIMARY_KEY" type="xs:positiveInteger"/>
    <xs:attribute name="LCID" type="xs:positiveInteger"/>
  </xs:complexType>
  <!-- FIELDTYPE -->
  <xs:simpleType name="FIELDTYPE">
    <xs:restriction base="xs:Name">
      <!-- observed in real life CDS XML: -->
      <xs:enumeration value="byte"/>
      <!-- from Delphi XE file dsxml.h: -->
      <xs:enumeration value="i1"/>
      <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="r10"/>
<!-- szXMLFloat/szXMLNumber <xs:enumeration value="r8"/> -->
      <xs:enumeration value="fixed"/>
      <xs:enumeration value="fixedFMT"/>
      <xs:enumeration value="boolean"/>
      <xs:enumeration value="date"/>
      <xs:enumeration value="dateTime"/>
      <xs:enumeration value="time"/>
      <xs:enumeration value="array"/>
      <xs:enumeration value="struct"/>
      <xs:enumeration value="nested"/>
      <xs:enumeration value="string.uni"/>
      <xs:enumeration value="string"/>
      <xs:enumeration value="bin.hex"/>
      <xs:enumeration value="IntArray"/>
      <xs:enumeration value="UIntArray"/>
      <xs:enumeration value="SQLdateTime"/>
      <xs:enumeration value="SQLdateTimeOffset"/>
    </xs:restriction>
  </xs:simpleType>
  <!-- subtype -->
  <xs:simpleType name="subtype">
    <xs:restriction base="xs:Name">
      <xs:enumeration value="Text"/>
      <xs:enumeration value="Binary"/>
      <xs:enumeration value="Formatted"/>
      <xs:enumeration value="Ole"/>
      <xs:enumeration value="Graphics"/>
      <xs:enumeration value="dBASEOle"/>
      <xs:enumeration value="TypedBinary"/>
      <xs:enumeration value="Money"/>
      <xs:enumeration value="Autoinc"/>
      <xs:enumeration value="AccessOle"/>
      <xs:enumeration value="HMemo"/>
      <xs:enumeration value="HBinary"/>
      <xs:enumeration value="ADTNestedTable"/>
      <xs:enumeration value="FixedChar"/>
      <xs:enumeration value="Reference"/>
      <xs:enumeration value="BFile"/>
      <xs:enumeration value="ADTDate"/>
      <xs:enumeration value="Guid"/>
      <xs:enumeration value="WideText"/>
      <!-- Binary is required for fieldtype="bin.hex" -->
      <!-- FixedChar is required for fieldtype="string" when the field is CHAR (but not NCHAR) -->
      <!-- Guid is required for fieldtype="string" when the field is GUID -->
      <!-- Text is required for fieldtype="bin.hex" when the underlying field is TEXT or NTEXT (memo?) -->
      <!-- Money is required for fieldtype="float" when the underlying field is CURRENCY -->
    </xs:restriction>
  </xs:simpleType>
  <!-- PARAM/param -->
  <xs:element name="PARAM" type="param"/>
  <xs:complexType name="param">
    <xs:attribute name="Name" type="paramName" use="required"/>
    <!-- two forms of Value are possible; xs:Name is for ORIGIN; xs:postiveInteger is for PROVFLAGS (in combination with Type)
        <xs:attribute name="Value" type="xs:Name" use="required"/>
        <xs:attribute name="Value" type="xs:postiveInteger" use="required"/>
-->
    <xs:attribute name="Value" type="xs:string" use="required"/>
    <xs:attribute name="Type" type="FIELDTYPE" use="optional"/>
    <xs:attribute name="Roundtrip" type="xs:Name" use="required" fixed="True"/>
  </xs:complexType>
  <!-- paramName -->
  <xs:simpleType name="paramName">
    <xs:restriction base="xs:Name">
      <xs:enumeration value="ORIGIN"/>
      <xs:enumeration value="PROVFLAGS"/>
    </xs:restriction>
  </xs:simpleType>
</xs:schema>

Regards.

这篇关于任何有部分XSD描述Delphi TClientDataSet XML文件的METADATA部分的人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆