You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Ke...@tertio.com on 2000/08/10 17:59:31 UTC
FAQs
All,
I would like some info on how to make the Xerces DOM parser (1.1.3)
validate some simple XML using a DTD. I am new to the XML world and
relatively new to the Java world.
I have set the relevant feature as follows:
domParser = new DOMParser();
try {
domParser.setFeature("http://xml.org/sax/features/validation", true);
} catch (SAXException e) {
System.out.println("error in setting up parser feature");
}
But when I parse some simple (and deliverately invalid) XML in a document that contradicts my DTD definitions it fails.
Just in case it's me being stupid, and not getting what XML validation using DTDs is all about, a little snippet if the XML file being parsed and the
DTD it references
are given below:
The DTD is:
<?xml encoding="US-ASCII"?>
<!ELEMENT Proc (Parameters,Comment?,FirstBlock,LastSequence)>
<!ATTLIST Proc
name CDATA #REQUIRED
seq ID #REQUIRED>
<!ELEMENT Parameters (Parameter)*>
<!ELEMENT Parameter (Type,Name)>
<!ELEMENT Type (#PCDATA)>
<!ELEMENT Name (#PCDATA)>
<!ELEMENT Comment (#PCDATA)>
<!ELEMENT FirstBlock (#PCDATA)>
<!ELEMENT LastSequence (#PCDATA)>
The XML file is:
<?xml version="1.0"?>
<!DOCTYPE STAN-test SYSTEM "test.dtd">
<Proc name="ManualLocationkev" seq="0">
<Parameters>
<Parameter>
<XType>byValue</XType>
<Name>smsMsg</Name>
</Parameter>
</Parameters>
<Comment>top level handling of SMS message</Comment>
<FirstBlock>1</FirstBlock>
<LastSequence>99</LastSequence>
</Proc>
My understanding is that the XML file is invalid based on the DTD file - as the "Parameter" element requires both a "Type"
and a "Name" element. However, when this file is parsed, the parser throws no exceptions.
I am missing something really basic ?
Thanks
Kev Shaw
Tertio Limited - One Angel Square, Torrens Street, London EC1V 1PL
Tel: +44 (0)207 843 4000 Fax: +44 (0)207 843 4001 Web http://www.tertio.com
Any views expressed in this message are those of the individual sender,
except where the sender specifically states them to be the views of Tertio Ltd.
Re: FAQs
Posted by Andy Clark <an...@apache.org>.
Kevin_Shaw@tertio.com wrote:
> I am missing something really basic ?
Create an ErrorHandler and register the handler so that you
receive callbacks based on the validation errors found in the
document.
--
Andy Clark * IBM, JTC - Silicon Valley * andyc@apache.org