OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: [xml-dev] Question on Allowing null values iin DTD

[ Lists Home | Date Index | Thread Index ]


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
________________________________________________________________________




 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS