1

How do I declare in this case the "coverimage" attribute of the element "book" in the XSD file? I would also like to restrict the "currency" attribute to the following currencies: dollars, euros, pounds with enumeration, by giving a type (xs:simpleType) definition. How do I do that?

Here is my XML:

<book coverimage="#">
  <title>Who cares</title>
  <autor>Doesn't Matter</autor>
  <price currency="euros">14.99</price>
  <year>1987</year>
</book>

Here is my XSD:

<xs:element name="book" minOccurs="0" maxOccurs="unbounded">
           <xs:complexType mixed="true">
             <xs:sequence>
                <xs:element name="title" type="xs:string"/>
                <xs:element name="autor" type="xs:string"/>
                <xs:element name="price">
                  <xs:complexType>
                    <xs:attribute name="currency" type="xs:string"/>
                  </xs:complexType>
                </xs:element>
                <xs:element name="year" type="xs:integer"/>
JavaApprentice
  • 101
  • 1
  • 2
  • 10
  • I was aware of this topic Mathias. It is very similar, but it doesn't solve my problem with defining the "coverimage" attribute. – JavaApprentice Feb 05 '17 at 17:23
  • 1
    What is the problem you are facing with the `coverimage` attribute? I see your XSD does not include a definition for `coverimage` anywhere. Why not? Also, please show a _complete_ XML schema document, not only part of it. Thanks. – Mathias Müller Feb 05 '17 at 17:27
  • The link @MathiasMüller provided covers the hard part; adding `coverimage` presents no further complication -- it's very routine. Closing until you [edit] and provide a [mcve] that explains how [XML Schema How to Restrict Attribute by Enumeration](http://stackoverflow.com/questions/8925706/xml-schema-how-to-restrict-attribute-by-enumeration) doesn't answer your question. – kjhughes Feb 05 '17 at 18:03

0 Answers0