0

I have the following xml for which I need XSD.

<?xml version="1.0" encoding="UTF-8"?>
 <Metadata>
  <Field Name="Claim Number">100</Field>
  <Field Name="Audit Year">2010</Field>
  <Field Name="Auditor Name">ABC PQR</Field>
</Metadata>

in the above xml if I delete <Field Name="Audit Year">2010</Field> this line then it must say "Audit Year" is not present in the given XML.

below is the present XSD but it's not a proper way.

<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
<xs:simpleType name="temp" >
<xs:restriction base="xs:string">
  <xs:enumeration value="Audit Year" />
</xs:restriction>

<xs:element name="Metadata">
<xs:complexType>
  <xs:sequence>
    <xs:element maxOccurs="unbounded" name="Field">
      <xs:complexType>
        <xs:simpleContent>
          <xs:extension base="xs:string">
           <xs:attribute name="Name" type="temp" use="required"/>
           <!--<xs:attribute name="Name" type="xs:string" use="optional" />-->
          </xs:extension>
        </xs:simpleContent>
      </xs:complexType>
    </xs:element>
  </xs:sequence>
</xs:complexType></xs:element></xs:schema>

1 Answers1

0

The simplest solution is to rename each Field name="X" element as X, so your XML is

<Metadata>
  <ClaimNumber>100</ClaimNumber>
  <AuditYear>2010</AuditYear>
  <Auditor>ABC PQR</Auditor>
</Metadata>

Now the task is trivial.

C. M. Sperberg-McQueen
  • 24,596
  • 5
  • 38
  • 65