Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XML
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old December 30th, 2015, 11:29 AM
Registered User
Points: 12, Level: 1
Points: 12, Level: 1 Points: 12, Level: 1 Points: 12, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2015
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default Lists

Hi,

I'm just foraying into XML for the first time and working on some practice scenarios. One of these includes making a representation of a tick list in XML, where a user could select none, one or more, or all options. I was looking at using list as my option. I have seen two different ways of writing it the Wrox "Beginning XML" method:

Code:
<simpleType name=”ContactTagsType”>
 <restriction base=”string”>
 <enumeration value=”author”/>
 <enumeration value=”xml”/>
 <enumeration value=”poetry”/>
 <enumeration value=”consultant”/>
 <enumeration value=”CGI”/>
 <enumeration value=”semantics”/>
 <enumeration value=”animals”/>
 </restriction>
 </simpleType>

with

<simpleType name=”ContactTagsListType”>
 <list itemType=”contacts:ContactTagsType”/>
 </simpleType>
And the W3Schools method which is similar (but I can't seem to get to work):

Code:
<xs:element name="intvalues" type="valuelist"/>
<xs:simpleType name="valuelist">
  <xs:list itemType="xs:integer"/>
</xs:simpleType>
</xs:schema>

The "intvalues" element in a document could look like this (notice that
the list will have five list items):

<intvalues>100 34 56 23 1567</intvalues>
Is there a preference of format? Also I think the latter doesn't work as I have no idea where to put the <intvalues> line :-/

Any pointers advice, would be greatly appreciated,

Gogs

Last edited by Gogs; December 30th, 2015 at 11:45 AM.
Reply With Quote
  #2 (permalink)  
Old December 30th, 2015, 11:54 AM
mhkay's Avatar
Wrox Author
Points: 18,252, Level: 58
Points: 18,252, Level: 58 Points: 18,252, Level: 58 Points: 18,252, Level: 58
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,929
Thanks: 0
Thanked 281 Times in 276 Posts
Default

Both of these are perfectly workable. Representing values as strings rather than integers is going to lead to fewer mistakes, so that would be my preference. One can't really advise on design questions without a lot more background knowledge about the project requirements and constraints.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Reply With Quote
The Following User Says Thank You to mhkay For This Useful Post:
Gogs (December 30th, 2015)
  #3 (permalink)  
Old December 30th, 2015, 11:57 AM
Registered User
Points: 12, Level: 1
Points: 12, Level: 1 Points: 12, Level: 1 Points: 12, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2015
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks, Michael. I thought that might be the case. If there's anything I have learnt in IT, it's that there is more than one way to skin a cat

With the W3schools example, though, where would the intvalues line fit in? The provided (similar) examples aren't clear on that point.
Reply With Quote
  #4 (permalink)  
Old December 30th, 2015, 12:28 PM
mhkay's Avatar
Wrox Author
Points: 18,252, Level: 58
Points: 18,252, Level: 58 Points: 18,252, Level: 58 Points: 18,252, Level: 58
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,929
Thanks: 0
Thanked 281 Times in 276 Posts
Default

The schema you've shown declares an intValues element. So it could be the root element of the document. If you want to use it within another element, you need to add a declaration of the other element to your schema, with intValues in its content model.

Note that's it's not essential to have a schema to describe your XML documents. You may find you can do useful things with XML more quickly if you don't worry about schemas until later.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Reply With Quote
  #5 (permalink)  
Old December 30th, 2015, 12:45 PM
Registered User
Points: 12, Level: 1
Points: 12, Level: 1 Points: 12, Level: 1 Points: 12, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2015
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks (again) that seems to be making sense :)
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT 2.0 Nesting lists inside lists by group unkown_varmit XSLT 9 April 12th, 2011 12:50 PM
Lists rickyoung Pro Visual Basic 2005 0 November 24th, 2006 08:04 AM
Lists Martyn Forum and Wrox.com Feedback 9 June 6th, 2003 11:03 AM
Email Lists Jeff Mason Forum and Wrox.com Feedback 43 June 5th, 2003 11:39 AM



All times are GMT -4. The time now is 06:29 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.