Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1020677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:11:48+00:00 2026-05-16T11:11:48+00:00

I have a simple XML file, with 3 basic elements. The first one is

  • 0

I have a simple XML file, with 3 basic elements. The first one is required (minOccurs=1) and the second and third are optional. However, if the second element is used, then I would like the make the third one required. He’s the XML:

<?xml version="1.0" encoding="utf-8" ?>
<resultado>
        <consulta fonte="1" origem="Origem">0</consulta>
        <status resultado="REGULAR">0</status>
        <informacoes>
                <informacao tipo="CPF" dado="23340058865"></informacao>
                <informacao tipo="Nome" dado="Nome Titular CPF"></informacao>
                <informacao tipo="Endereco" dado="Rua Sem Fim, 48"></informacao>
                <informacao tipo="Cidade" dado="Fim do Mundo"></informacao>
                <informacao tipo="Estado" dado="TO"></informacao>
                <informacao tipo="Cep" dado="93847832"></informacao>
                <informacao tipo="Fone" dado="5938476354"></informacao>
        </informacoes>
</resultado>

If the status element is passed, then informacoes becomes a required element.
Below is my XSD:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:simpleType name="codigoresultado">
        <xs:restriction base="xs:unsignedByte">
            <xs:enumeration value="0"/>
            <xs:enumeration value="1"/>
            <xs:enumeration value="2"/>
            <xs:enumeration value="3"/>
            <xs:enumeration value="4"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="resultadoconsulta">
        <xs:restriction base="xs:unsignedByte">
            <xs:enumeration value="0"/>
            <xs:enumeration value="1"/>
            <xs:enumeration value="2"/>
            <xs:enumeration value="3"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:element name="resultado">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="consulta" minOccurs="1" maxOccurs="1">
                    <xs:complexType>
                        <xs:simpleContent>
                            <xs:extension base="resultadoconsulta">
                                <xs:attribute name="fonte" type="xs:integer" use="required" />
                                <xs:attribute name="origem" type="xs:string" use="required" />
                            </xs:extension>
                        </xs:simpleContent>
                    </xs:complexType>
                </xs:element>
                <xs:element name="status" minOccurs="0" maxOccurs="1">
                    <xs:complexType>
                        <xs:simpleContent>
                            <xs:extension base="codigoresultado">
                                <xs:attribute name="resultado" type="xs:string" use="required" />
                            </xs:extension>
                        </xs:simpleContent>
                    </xs:complexType>
                </xs:element>
                <xs:element name="informacoes" minOccurs="0" >
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element minOccurs="1" maxOccurs="unbounded" name="informacao">
                                <xs:complexType>
                                    <xs:attribute name="tipo" type="xs:string" use="required" />
                                    <xs:attribute name="dado" type="xs:string" use="required" />
                                </xs:complexType>
                            </xs:element>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

Is that possible? If it is, how?
Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T11:11:48+00:00Added an answer on May 16, 2026 at 11:11 am

    The only way I would see is to bundle up these two elements into a <xs:sequence> of their own which would be optional.

    If it’s present, then both elements have to be present (or both can be left out).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a simple xml file in a wcf service that i am trying
I have a simple xml file and I want to remove everything before the
I have this simple XML file : <?xml version=1.0 encoding=utf-8 ?> <Artists> <artist artistId=1>
I have a really simple XML file that I'm trying to read, but I
I have written simple code to get content from xml file to php. $xml
I have a large xml file (approx. 10 MB) in following simple structure: <Errors>
I have a map that reads an XML file; it's all very simple and
I have a sample xml file which looks like the one below: <Root> <SubOne>
I have a simple XML file as shown below. <?xml version=1.0 encoding=UTF-8?> <myConfig> <datasets>
I have a basic XML file that I load in my PHP using $xml

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.