Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable length lists

Status
Not open for further replies.

DaedalusPrime

Programmer
May 25, 2005
13
0
0
US
I don't have a lot of experience with XML, but I'd like to create a schema that includes an element for which I can have an arbitrary number of values, i.e. maybe only 5 values for one file based on the schema, but 25 for another.

I'd prefer to not put some hard and fast limit on the number if possible.

Thanks!
 
What do you mean by values?

Jon

"There are 10 types of people in the world... those who understand binary and those who don't.
 
I'm trying to store data in a spreadsheet or database style.

For example, let's say I need to store information on various parts. Each row's leftmost column would have something like a Part Number, and the other 10 columns or so would store information on the various attributes of this part. I don't know how many parts I will have, but I'd like to store each number and attribute under a separate element name in my schema, such that I might have elements called PARTNO, THICKNESS, MAXTEMP and so on. I'd like to store each set (or row) of these values, but want to avoid having a whole slew of elements like PARTNO_0, PARTNO_1, PARTNO_2, and so on.
 
So you would like to have a structure like this:
Code:
<parts>
  <part id="1">
    <thickness>float?</thickness>
    <maxtemp>integer?</maxtemp>
  </part>
  <part id="2">
    ..some possibly different elements...
  </part>
</parts>
Will all the different types be known or do you want to allow arbituary elements?

Jon

"There are 10 types of people in the world... those who understand binary and those who don't.
 
All the types will be known. Each part would have the same elements in the same quantity ie:
Code:
<parts>
  <part id="1">
    <thickness>float?</thickness>
    <maxtemp>integer?</maxtemp>
  </part>
  <part id="2">
    <thickness>float?</thickness>
    <maxtemp>integer?</maxtemp>
  </part>
  .
  .
  .
  <part id=x>
    <thickness>float?</thickness>
    <maxtemp>integer?</maxtemp>
  </part>
</parts>

where X is the number of the last set of elements that the user has defined. All I want to do is define a schema that would describe a structure like this.

 
After doing some more searching on the web, I found this page which seems to describe what I want to do fairly well. To quote a code snippet from their example:
Code:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema">[/URL]
  <xs:element name="book">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="title" type="xs:string"/>
        <xs:element name="author" type="xs:string"/>
        <xs:element name="character" minOccurs="0" maxOccurs="unbounded">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="name" type="xs:string"/>
              <xs:element name="friend-of" type="xs:string" minOccurs="0"
			       maxOccurs="unbounded"/>
              <xs:element name="since" type="xs:date"/>
              <xs:element name="qualification" type="xs:string"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
      <xs:attribute name="isbn" type="xs:string"/>
    </xs:complexType>
  </xs:element>
</xs:schema>

They go into more detailed examples of how to do some more advanced schema tasks, but this simple example is probably enough for my application. If you have any other suggestions after seeing this, let me know.

Thanks for your help!
 
Possible schema:
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema">[/URL]
  <xs:element name="parts">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="part" minOccurs="1" maxOccurs="unbounded">
          <xs:complexType>
            <xs:all>
              <xs:element name="thickness" type="xs:decimal" minOccurs="0"/>
              <xs:element name="maxtemp" type="xs:integer" minOccurs="0"/>
            </xs:all>
            <xs:attribute name="id" type="xs:integer"/>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

Jon

"There are 10 types of people in the world... those who understand binary and those who don't.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top