Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 30th, 2015, 12:29 PM
Registered User
 
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 12:45 PM..
 
Old December 30th, 2015, 12:54 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 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
The Following User Says Thank You to mhkay For This Useful Post:
Gogs (December 30th, 2015)
 
Old December 30th, 2015, 12:57 PM
Registered User
 
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.
 
Old December 30th, 2015, 01:28 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 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
 
Old December 30th, 2015, 01:45 PM
Registered User
 
Join Date: Dec 2015
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks (again) that seems to be making sense :)





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 09: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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.