Domanda

I have a question regarding defining new attribute for my elements in my xml schema (xsd) I have an element like this

<xs:element name="xyz" type="xs:hexBinary" minOccurs="2">

I want to add a new attribute "size" where I can specify the size of the element "xyz". How can I define do this?

Thanks for your help

È stato utile?

Soluzione

Below is a simple valid XSD, built around your xyz element.

<?xml version="1.0" encoding="utf-8" ?>
<!-- XML Schema generated by QTAssistant/XSD Module (http://www.paschidev.com) -->
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xs:complexType name="dummy">
        <xs:sequence>
            <xs:element name="xyz" minOccurs="2">
                <xs:complexType>
                    <xs:simpleContent>
                        <xs:extension base="xs:hexBinary">
                            <xs:attribute name="size" type="xs:int" use="required"/>
                        </xs:extension>
                    </xs:simpleContent>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:schema>

Any element that has attributes and/or nested elements MUST be of complex type. If there are nested elements, then the content model of the complex type must be complexContent; otherwise, it must be simpleContent.

This approach doesn't allow you to also constrain the base type (here hexBinary). If you need to also specify constraining facets for the simple base type, then you have to separately create a new simple type, a restriction of hexBinary, and then extend the new type with attributes.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top