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

  • Home
  • SEARCH
  • 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 7039591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:49:01+00:00 2026-05-28T01:49:01+00:00

Below is the sample xml which has multiple <rulex> that starts with sequence 1

  • 0

Below is the sample xml which has multiple <rulex> that starts with sequence 1 and it can end up to many rule like <rule1> , <rule2>, <rule3> etc….

<?xml version="1.0" encoding="UTF-8"?>
<AddressChange_181>
    <rules>
        <rule1>
            <conditions>xya</conditions>
            <response_path>abc</response_path>
        </rule1>
        <rule2>
            <conditions>xxxx</conditions>
            <response_path>aaaa</response_path>
        </rule2>
        <rule3>
            <conditions>yyyyy</conditions>
            <response_path>ffff</response_path>
        </rule3>
        <rule4>
            <conditions>zzzz</conditions>
            <response_path>yyyy</response_path>
        </rule4>
        <default>
            <response_path>uuuuu</response_path>
        </default>
    </rules>
</AddressChange_181>

Below is the schema where i tried creating dynamic <rulex> element name for the above xml.
when i generate xml from this schema i do not get the same xml format as above xml.
can you please let me know how to create schema with multiple element name that starts with a sequence number.
My requirement is to add more than one rule (<rule1>,<rule2>,<rule3> etc…) in xml file and this xml file should be validated against schema.

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="mock_rule_list"> 
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="rules" minOccurs="1" maxOccurs="1"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="rules">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="rule" minOccurs="0" maxOccurs="unbounded"/>        
        <xs:element ref="default" maxOccurs="1"/>
      </xs:sequence>
    </xs:complexType>   
  </xs:element>

  <xs:element name="rule">    
    <xs:complexType>  
    <xs:simpleContent>
      <xs:restriction base="xs:anyType">
        <xs:pattern value="rule/d{1,3}"></xs:pattern>
      </xs:restriction>
    </xs:simpleContent>      
      <xs:sequence>
        <xs:element ref="conditions" minOccurs="1" maxOccurs="1"/>
        <xs:element ref="response_path" minOccurs="1" maxOccurs="1"/>
      </xs:sequence>
    </xs:complexType>   

  </xs:element>

  <xs:element name="default">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="response_path"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="conditions" type="xs:string">   
  </xs:element>
  <xs:element name="response_path" type="xs:string"/>
</xs:schema>

Thanks,
Madhu

  • 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-28T01:49:02+00:00Added an answer on May 28, 2026 at 1:49 am

    There is no way to define such a structure using XSD if the number of ruleX tags is arbitrarily defined. If you can constrain the upper bound to a maximum, and you really have to stick with ruleX naming convention, than you can define a complex type such as ruleType, then a bunch of rule1, rule2,… , ruleN elements of that type – I would call this messy… I wouldn’t recommend this.

    XSD (with a maximum of 6):

    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
        <xs:element name="mock_rule_list">
            <xs:complexType>
                <xs:sequence>
                    <xs:element ref="rules" minOccurs="1" maxOccurs="1"/>
                </xs:sequence>
            </xs:complexType>
        </xs:element>
    
        <xs:element name="rules">
            <xs:complexType>
                <xs:sequence>
                    <xs:element ref="rule1" minOccurs="0"/>
                    <xs:element ref="rule2" minOccurs="0"/>
                    <xs:element ref="rule3" minOccurs="0"/>
                    <xs:element ref="rule4" minOccurs="0"/>
                    <xs:element ref="rule5" minOccurs="0"/>
                    <xs:element ref="rule6" minOccurs="0"/>
                    <xs:element ref="default"/>
                </xs:sequence>
            </xs:complexType>
        </xs:element>
    
    
        <xs:complexType name="ruleType">
            <xs:sequence>
                <xs:element ref="conditions" minOccurs="1" maxOccurs="1"/>
                <xs:element ref="response_path" minOccurs="1" maxOccurs="1"/>
            </xs:sequence>
        </xs:complexType>
    
        <xs:element name="default">
            <xs:complexType>
                <xs:sequence>
                    <xs:element ref="response_path"/>
                </xs:sequence>
            </xs:complexType>
        </xs:element>
        <xs:element name="conditions" type="xs:string">
        </xs:element>
        <xs:element name="response_path" type="xs:string"/>
    
        <xs:element name="rule1" type="ruleType"/>
        <xs:element name="rule2" type="ruleType"/>
        <xs:element name="rule3" type="ruleType"/>
        <xs:element name="rule4" type="ruleType"/>
        <xs:element name="rule5" type="ruleType"/>
        <xs:element name="rule6" type="ruleType"/>
    </xs:schema>
    

    Alternatively, you could have a tag named “rule” with a @sequence attribute.

    XSD:

    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
        <xs:element name="mock_rule_list">
            <xs:complexType>
                <xs:sequence>
                    <xs:element ref="rules" minOccurs="1" maxOccurs="1"/>
                </xs:sequence>
            </xs:complexType>
        </xs:element>
    
        <xs:element name="rules">
            <xs:complexType>
                <xs:sequence>
                    <xs:element ref="rule" minOccurs="0" maxOccurs="unbounded"/>
                    <xs:element ref="default"/>
                </xs:sequence>
            </xs:complexType>
            <xs:unique name="SequenceKey">
                <xs:selector xpath="rule"/>
                <xs:field xpath="@sequence"/>
            </xs:unique>
        </xs:element>
    
        <xs:complexType name="ruleType">
            <xs:sequence>
                <xs:element ref="conditions" minOccurs="1" maxOccurs="1"/>
                <xs:element ref="response_path" minOccurs="1" maxOccurs="1"/>
            </xs:sequence>
            <xs:attribute name="sequence" type="xs:int" use="required"/>
        </xs:complexType>
    
        <xs:element name="default">
            <xs:complexType>
                <xs:sequence>
                    <xs:element ref="response_path"/>
                </xs:sequence>
            </xs:complexType>
        </xs:element>
        <xs:element name="conditions" type="xs:string">
        </xs:element>
        <xs:element name="response_path" type="xs:string"/>
    
        <xs:element name="rule" type="ruleType"/>
    </xs:schema>
    

    Sample XML:

    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <!-- Sample XML generated by QTAssistant (http://www.paschidev.com) -->
    <rules xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <rule sequence="1">
            <conditions>conditions1</conditions>
            <response_path>response_path1</response_path>
        </rule>
        <rule sequence="2">
            <conditions>conditions2</conditions>
            <response_path>response_path2</response_path>
        </rule>
        <default>
            <response_path>response_path1</response_path>
        </default>
    </rules>
    

    Or it could also be that one could simply use the index of the <rule/> within the parent collection .

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

Sidebar

Related Questions

I have a XML which has multiple records. I would like to populate those
I have a bit of xml file named Sample.xml which is shown below <?xml
In the sample code below I am dividing by zero which when I step
The code below shows a sample that I've used recently to explain the different
Below I have written a sample program that I have written to learn about
How do I save a large collection with NHibernate which has elements that surpass
I have the below fragement of XML, notice that the Reference node holds a
I have a XML like this: <?xml version=1.0 encoding=UTF-8?> <nodes> <n c=value2/> <n>Has a
A test sample of my xml file is shown below: test.xml <feed> <entry> <title>Link
I have a sample code in which i am trying to validate a 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.