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

Re: Question on Allowing null values iin DTD


index with null values

me> If you are wanting to model
me>a database entry that may be null, there are several ways that you may
me>do this, by allowing the element to be empty

> MyQuestion:

> How can we do that? Empty values don't allow the values at all..

If your entry can be an integer or null then traditionally in a dtd you
would just have some element declared as 
<!ELEMENT x (#PCDATA)>

then in your application you would code knowledge that if it looks like 
<x>123</x> then it's the integer 123, if it looks like <x></x> (or <x/>)
then it's null, and if it looks like <x>hello world</x> then it's an
error. The DTD validation would pass all of these, but raise a validity
error on something like <x><y/></x>.

If you want your XML parsing layer to do more, for example give an error
on <x>hello world</x> then you need to look to a schema language rather
than DTD in which you can constrain the content to be a valid integer
for example. But you still have completly free choice about how you
encode the null value, you could use x being empty <x/> or x having
a specific child element <x><null/></x> or attribute <x xsi:nil="true"/>
or denote it by the <x> element being absent completely. It's your
choice. How you choose to model null will affect whether errors are
checked at the dtd or schema level or in your application, but there are
no definite rules and different people make different choices. You don't
have to have a dtd or schema at all. If you know your XML is being
written out by some application in a regular manner You can just output
well formed XML and code your application to accept the regular format
that you expect and give errors in other cases. If you use a schema you
may be able to use tools to generate part of your application code for
you, extracting the data from the XML and binding it to appropriate
constructs in whatever programming language you are using, but whether
that is appropriate is again a matter of personal choice. For an old
time SGML/document person like me, it's not the way I usually approach
XML, but if this is data oriented xml from a database, I'm probably not
the person whose experience you should be basing your decisions on:-)


David


________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

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
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

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.