Thema: Delphi xsd Validierung

Einzelnen Beitrag anzeigen

Robert_G
(Gast)

n/a Beiträge
 
#5

Re: xsd Validierung

  Alt 6. Aug 2004, 11:54
Falls du damit meinst, du willst nur halbwegs glaubwürdige Daten bzw. keine groben Eingabefehler/FK- oder PK-Verletzungen, dann dürfte XSD die Wahl sein.

Ich habe hier mal einen Auszug meines ersten funktionstüchtigen XSD für .Net angefügt.
Ist schon etwas älter, aber noch lesbar. Meine jetzigen Schemata sind ziemlich groß (das VS hat zum Glück einen visuellen XSD Designer )

XML-Code:
<?xml version="1.0" standalone="yes" ?>
<xs:schema id="dsImportMe"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
    attributeFormDefault="qualified"
    elementFormDefault="qualified">
    <xs:element name="dsImportMe" msdata:IsDataSet="true">
        <xs:complexType>
            <xs:choice maxOccurs="unbounded">
                <xs:element name="DEMOGRAPHY">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="SUBJECT_ID" type="xs:int" minOccurs="0" />
                            <xs:element name="SUBJID" minOccurs="0" >
                                <xs:simpleType>
                                    <xs:restriction base="xs:string">
                                        <xs:maxLength value="8" />
                                    </xs:restriction>
                                </xs:simpleType>
                            </xs:element>
                            <xs:element name="COUNTRY" type="xs:decimal" minOccurs="0" />
                            <xs:element name="SEXCD" type="xs:int" minOccurs="0" />
                            <xs:element name="SITEID" type="xs:decimal" minOccurs="0" />
                            <xs:element name="RACECD" type="xs:int" minOccurs="0" />
                            <xs:element name="RACEOTH" minOccurs="0" >
                                <xs:simpleType>
                                    <xs:restriction base="xs:string">
                                        <xs:maxLength value="20" />
                                    </xs:restriction>
                                </xs:simpleType>
                            </xs:element>
                            <xs:element name="BIRTHDT" type ="xs:dateTime" minOccurs="0" />
                            <xs:element name="TEMP" minOccurs="0" >
                                <xs:simpleType>
                                    <xs:restriction base="xs:decimal">
                                        <xs:totalDigits value="3"/>
                                        <xs:fractionDigits value="1"/>
                                        <xs:minInclusive value="36.5"/>
                                        <xs:maxInclusive value="40.5"/>
                                    </xs:restriction>
                                </xs:simpleType>
                            </xs:element>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
                <xs:element name="RACECD">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="Code" type="xs:int" />
                            <xs:element name="Label" type="xs:string"/>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
                <xs:element name="SEXCD">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="Code" type="xs:int" />
                            <xs:element name="Label" type="xs:string"/>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:choice>
        </xs:complexType>
        
        <xs:unique name="PK_DEMO" msdata:PrimaryKey="true">
            <xs:selector xpath=".//DEMOGRAPHY" />
            <xs:field xpath="SUBJECT_ID" />
        </xs:unique>
        
        <xs:unique name="PK_Format_RACECD" msdata:PrimaryKey="true">
            <xs:selector xpath=".//RACECD" />
            <xs:field xpath="Code" />
        </xs:unique>
        <xs:unique name="PK_Format_SEXCD" msdata:PrimaryKey="true">
            <xs:selector xpath=".//SEXCD" />
            <xs:field xpath="Code" />
        </xs:unique>
        
        <xs:keyref name="FK_Format_RACECD_DEMO" refer="PK_Format_RACECD" msdata:ConstraintOnly="true"
                   msdata:UpdateRule="None" msdata:DeleteRule="None">
            <xs:selector xpath=".//DEMOGRAPHY" />
            <xs:field xpath="RACECD" />
        </xs:keyref>
        <xs:keyref name="FK_Format_SEXCD_DEMO" refer="PK_Format_SEXCD" msdata:ConstraintOnly="true"
                   msdata:UpdateRule="None" msdata:DeleteRule="None">
            <xs:selector xpath=".//DEMOGRAPHY" />
            <xs:field xpath="SEXCD" />
        </xs:keyref>
    </xs:element>
</xs:schema>
  Mit Zitat antworten Zitat