The ref attribute of an xml schema document element

0

I'm doing an xml file generator xs, but I'm not sure if some parts should be populated.

<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 template must be present and can not be repeated.

Must the provider and request elements have the ref = attribute filled in?

For example:

  • 1 form for the name = template.

  • 1 form for ref = identification.

  • How many forms do you want for ref = provider.

Is that right?

    
asked by anonymous 27.02.2015 / 22:10

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 ID must have a unique template.

Yes, the ref attribute you need in this case. It means that you refer to complex type - that way, you can use that complex type in another part of your XSD without having to type it again. If you do not need to take advantage of it, you can do the following to avoid 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.

    
05.04.2015 / 17:15