You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Nikhil Dinesh <ni...@seas.upenn.edu> on 2004/06/08 02:48:25 UTC

Re: How to validate required attributes

It  may be the case that there is a mistake in your ErrorHandler. If you
put xercesSamples.jar in your classpath and run java dom.Counter -v file
it will print out the errors. Then look in the samples/dom/wrappers
directory. There is a file Xerces.java which implements ErrorHandler.

That should give you some idea.
Hope this helps.


On Mon, 7 Jun 2004, Chris Borchert wrote:

>
>  I'm using Xerces 2.5 and have a DOMParser loading a file and validating
> against a DTD. I have an ErrorHandler set plus the validation feature set
> to true. If I do something like <cell x="1" y="1">data</cell2> I correctly
> get an error. However, I get no errors or warnings with a <cell>data</cell>
> which is missing its required attributes, correct? Does the DOMParser
> validate required attributes?
>
> Likewise, I don't get an error when sub-elements are missing. E.g.,
> shouldn't <grid> be required to have a <symbols> child? But when I leave
> out <symbols>data</symbols> it doesn't complain.
>
> Thanks,
> Chris
>
>
> Part of my XML:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE grid SYSTEM "jks1_0.dtd">
> <grid height="10" version="1.0" width="10">
>     <symbols>burda.symbols</symbols>
>     <cell x="1" y="1">
>         <symbol>2</symbol>
>     </cell>
> ...
>     <cell x="10" y="10">
>         <nosymbol/>
>     </cell>
> </grid>
>
>
> My DTD:
>
> <!ELEMENT grid (symbols+, cell+)>
> <!ATTLIST grid
>     version CDATA #REQUIRED
>     width CDATA #REQUIRED
>     height CDATA #REQUIRED>
> <!ELEMENT symbols (#PCDATA)>
> <!ELEMENT cell (symbol | text | nosymbol | widesymbol)>
> <!ATTLIST cell
>     x CDATA #REQUIRED
>     y CDATA #REQUIRED>
> <!ELEMENT symbol (#PCDATA)>
> <!ELEMENT text (#PCDATA)>
> <!ELEMENT nosymbol EMPTY>
> <!ELEMENT widesymbol EMPTY>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail:
> xerces-j-user-help@xml.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org