SaliproPham
SaliproPham

Reputation: 163

xsd restriction and attribute

Learning xml, Can anyone help me? I have following XML code:

**<book lang="en">name of book</book>**

i want to write a xsd file with constraint:

book tag with

Help!! Thank everybody

Upvotes: 0

Views: 535

Answers (1)

Petru Gardea
Petru Gardea

Reputation: 21658

This XSD should do:

<?xml version="1.0" encoding="utf-8"?>
<!--W3C Schema generated by QTAssistant/W3C Schema Refactoring Module (http://www.paschidev.com)-->
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:element name="book">
        <xsd:complexType>
            <xsd:simpleContent>
                <xsd:extension base="String5To30">
                    <xsd:attribute name="lang" type="xsd:string" use="required"/>
                </xsd:extension>
            </xsd:simpleContent>
        </xsd:complexType>
    </xsd:element>
    <xsd:simpleType name="String5To30">
        <xsd:restriction base="xsd:string">
            <xsd:maxLength value="30"/>
            <xsd:minLength value="5"/>
        </xsd:restriction>
    </xsd:simpleType>
</xsd:schema>

The way I did it was to automatically generate an XSD from your XML fragment; then add the simple type that gives you the restriction vis-a-vis lengths.

Upvotes: 1

Related Questions