The ref attribute of an element of the xml schema document

Asked

Viewed 224 times

0

I’m making an Xs xml file generator, but I’m wondering if some parts should be filled.

<xs:element name="identificacao">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="modelo"></xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:element>

<xs:element name="prestador">
    <xs:complexType>
        <xs:sequence>
            <xs:element ref="identificacao"></xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:element>

<xs:element name="solicitacao">
    <xs:complexType>
        <xs:sequence>
            <xs:element ref="prestador" minOccurs="1" maxOccurs="unbounded"></xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:element>

The model has to be present and cannot be repeated.

The elements provider and solicitation must have the attribute ref= filled?

For example:

  • 1 form for name=template.

  • 1 form for ref=identification.

  • How many forms you want for ref=provider.

That’s right?

  • Jobson, to help you (and who else will read this in the future), is that what you want to know? Each request must have n providers. Each provider shall have 1 identification. Each identification shall have 1 model.

1 answer

2

Your XSD validates the following XML:

<?xml version="1.0" encoding="UTF-8"?>
<solicitacao xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="file:///C:/Users/PeerBr/Desktop/test.xsd">
    <prestador>
        <identificacao>
            <modelo/>
        </identificacao>
    </prestador>
    <prestador>
        <identificacao>
            <modelo/>
        </identificacao>
    </prestador>
</solicitacao>

In short:

  • One request per file
  • Each request must have at least one provider
  • Each provider must have a unique identification
  • Each identification has to have a unique model.

Yes, the attributo ref you need in this case. It designates that you refer to a complex type - this way, you can use this complex type elsewhere in your XSD without having to write again. If you don’t need to take advantage of it, you can do the following to avoid the ref:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:element name="solicitacao">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="prestador" minOccurs="1" maxOccurs="unbounded">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="identificacao">
                                <xs:complexType>
                                    <xs:sequence>
                                        <xs:element name="modelo"/>
                                    </xs:sequence>
                                </xs:complexType>
                            </xs:element>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

Both ways validate equally.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.