[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Creation of DTD

Subject: RE: Creation of DTD
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 19 Aug 2005 16:31:58 +0100
RE:  Creation of DTD
DTDs only allow you to constrain the order of elements by name, not by
value. In fact even XML Schema, which goes further than DTDs in contraining
what the values of elements and attributes can be, doesn't allow you to
constrain the ordering based on values.

To bring it back to be on-topic, it's often quite useful to use stylesheets
for validation. Write template rules that produce error messages:

<xsl:template match="row">
  <xsl:if test="not(item[1]/@name='Price')">
    <error>First item in row must be Price</error>
  </xsl:if>
  <xsl:if test="not(item[2]/@name='Item')">
    <error>Second item in row must be Item</error>
  </xsl:if>

etc.

For a higher-level tool based on this approach, see Schematron.

Michael Kay
http://www.saxonica.com/

> -----Original Message-----
> From: Verakso [mailto:verakso@xxxxxxxxx] 
> Sent: 19 August 2005 14:24
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Creation of DTD
> 
> I not quite sure if creation of DTD's is out of the scope of this
> list, if so kindly point me in the right decision.
> 
> My problem is, first I am a bit rusty in writing DTD's, second, I not
> even sure I can do what I want with a DTD, perhaps a Schema was more
> appropriate.
> 
> The scenario is as follows. From a system, I get a CSV file, which is
> converted into a XML file, like:
> <data>
> 	<row count="1">
> 		<item name="Price">5</item>
> 		<item name="Item">Football</item>
> 		<item name="SKU">1010</item>
> 	</row>
> 	<row count="2">
> 		<item name="Price">15</item>
> 		<item name="Item">Basket Ball</item>
> 		<item name="SKU">1012</item>
> 	</row>
> 	<row count="n">
> 		<item name="Price">10</item>
> 		<item name="Item">ball</item>
> 		<item name="SKU"></item>
> 	</row>
> </data>
> 
> What I would like to do, is to make a DTD so I can check if the item
> elements is present, and in that order. CSV is not at "strong" as XML,
> and I would like to test up front, if the column names has been
> changed in the CSV import.
> 
> But AFAIK, it is not possible to write a DTD that specifies the order
> and requirements of the name attributes, or am I wrong?
> 
> /Thomas

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.