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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T13:09:58+00:00 2026-05-22T13:09:58+00:00

I am using xsd to generate classes from an xml file. It is working

  • 0

I am using xsd to generate classes from an xml file. It is working ok but there is one part of the xml file that is not being generated as I would like.

Here is a sample section of the xml:

<Product>
  <p0>Stapler</p0>
  <p1>1.50</p1>
  <p2>0</p2>
</Product>

In the xsd that was generated form the xml, I see this section:

<xs:element name="Product" minOccurs="0" maxOccurs="unbounded">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="p0" type="xs:string" minOccurs="0" />
      <xs:element name="p1" type="xs:decimal" minOccurs="0" />
      <xs:element name="p2" type="xs:decimal" minOccurs="0" />      
    </xs:sequence>
  </xs:complexType>
</xs:element>

The problem here is that the xml responses I am trying to deserialize will have varying numbers of elements in the Product section. In the above example, it goes from p0 to p2. Other responses may go from p0 to p8.

Is there a way for me to generate a my class so that it can handle a variable number of elements for the Product?

  • 1 1 Answer
  • 2 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-22T13:09:59+00:00Added an answer on May 22, 2026 at 1:09 pm

    You have two options:

    1. If you want to keep your simplicity, and the order of the elements is always the same types (so it’s always string, decimal, int, etc) then just generate the schema using the Product type with all 8.

    2. Make your schema more complex, and make the “Product” a list of ProductTypes (which would define what each product is).

    Something like:

    <Product>
      <ProductType id="name" _type="xs:string">
           <Value>Stapler</Value>
      </ProductType>
      <ProductType id="cost" _type="xs:decimal">
           <Value>1.50</Value>
      </ProductType>
       <ProductType id="quantity" _type="xs:decimal">
           <Value>0</Value>
      </ProductType>
    </Product>
    

    It’s xml so there are tons of good ways to do this.

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

Sidebar

Related Questions

Our project uses XJC to generate Java classes from an XSD. I'm using JAVA
What are the options to generate .NET 4.0 c# classes (entities) from an xsd
I'm trying to generate an XML document using a class generated by the xsd.exe
I am using the Ecore model which is based on imported XML Schema file
I generated classes using xjc, and I am trying to process the following XML
Is there a T4 template to generate a typed dataset? I am using NDBUnit
I have a rather large XSD file and I have heard that it is
I have a maven library project with some classes to deal xml messages. Whenever
I'm using the svcutil tool to generate a set of proxies for a 3rd
I know this isn't the best place to put this question but here it

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.