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 8455981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:25:45+00:00 2026-06-10T12:25:45+00:00

I am having problem in writing a xsd file for validating an specific XML

  • 0

I am having problem in writing a xsd file for validating an specific XML format. The XML format goes like this:

<?xml version="1.0" encoding="UTF-8"?>
<p:customers xmlns:p="http://www.w3schools.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3schools.com NewXMLSchema.xsd ">
<p:customer>
   <p:name salutation="Mr."/>
   <p:age>25</p:age>
   <p:discount>6</p:discount>
</p:customer>
<p:customer>
   <p:name salutation="Ms."/>
   <p:age>35</p:age>
   <p:discount>10</p:discount>
</p:customer>
........
........
</p:customers>

The number of customer will vary; it may be one or more.

This is the XSD i came up with for validating this XML:

<xs:complexType name="customerName">
    <xs:attribute name="salutation" type="xs:string" default="Mr."></xs:attribute>
</xs:complexType>

<xs:simpleType name="customerAge">
    <xs:restriction base="xs:integer">
        <xs:minInclusive value="18"></xs:minInclusive>
        <xs:maxInclusive value="60"></xs:maxInclusive>
    </xs:restriction>
</xs:simpleType>

<xs:simpleType name="customerdiscount">
    <xs:restriction base="xs:integer">
        <xs:minInclusive value="5"></xs:minInclusive>
        <xs:maxInclusive value="30"></xs:maxInclusive>
    </xs:restriction>
</xs:simpleType>

<xs:complexType name="customer">
    <xs:sequence>
        <xs:element name="name" type="customerName"></xs:element>
        <xs:element name="age" type="customerAge"></xs:element>
        <xs:element name="discount" type="customerdiscount"></xs:element>
    </xs:sequence>
</xs:complexType>

<xs:element name="customers">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="customer" type="customer"></xs:element>
            <xs:element name="customer" type="customer"></xs:element>
            <xs:element name="customer" type="customer"></xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:element>

In the above XSD, i am facing a few problems, need the resolutions:

1) I want the name to be something like this:

<name salutation="Mr.">XYZ NAme</name>

2) The customer names may be one or more. In the above code, i used sequence and hence there can be 3 and only 3 customer. This thing I need to rectify.

Please help me with these two stuff in XSD.

Regards,

  • 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-06-10T12:25:47+00:00Added an answer on June 10, 2026 at 12:25 pm

    I hope this helps:

    1) You can extend xs:string as a complex type with an attribute:

     <xs:element name="name">
       <xs:complexType>
         <xs:simpleContent>
           <xs:extension base="xs:string">
             <xs:attribute name="salutation" type="xs:string"/>
           </xs:extension>
         </xs:simpleContent>
       </xs:complexType>
     </xs:element>
    

    2) You can use minOccurs and maxOccurs:

    <xs:element name="customer" type="customer" minOccurs="1" maxOccurs="unbounded"/>
    

    Also, I think you need to specify the schema’s target namespace at the top:

    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
               elementFormDefault="qualified"
               targetNamespace="http://www.w3schools.com"
               xmlns:p="http://www.w3schools.com">
    

    and prefix type references with p (because all types defined by the schema are in the target namespace):

     <xs:element name="age" type="p:customerAge"/>
     <xs:element name="discount" type="p:customerdiscount"/>
     <xs:element name="customer" type="p:customer" minOccurs="0" maxOccurs="unbounded"/>
    

    With these changes, I could successfully validate the document above (with the dots removed).

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

Sidebar

Related Questions

I'm having a problem writing Norwegian characters into an XML file using C#. I
i'm having problem writing to a text file using php. this might sound simple
I'm having some problem writing a tab delimited string into a txt file. //This
I'm having a problem writing to a file: FileInputStream fin; try { fin =
I am having a problem with a file i am writing too, basically what
Hi I am having no problem writing to or appending to a file, the
I'm having this problem while writing my own HashTable. It all works, but when
I'm having a problem with arrays and file writing, what I want to do
I am having a problem writing a string like a word Zürich the output
I'm having a major problem with writing values into a new CSV file. I

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.