Re: How to parse an xform document with Xerces?

How to parse an xform document with Xerces?Comments inline

----- Original Message -----
From: Naresh Bhatia
To: 'www-forms@w3.org'
Sent: Sunday, November 25, 2001 11:12 PM
Subject: How to parse an xform document with Xerces?


I am a newbie to xforms and xml schema. Just for kicks, I am trying to parse
the xml document in section 2.7 of the xform spec using the Xerces Java
Parser 1.4.4. I have set validating and namespaceAware to true. However I am
not getting too far with this exercise. Can someone help?

1) The first error I got was on line 2, which is the <!DOCTYPE> tag:
01 <?xml version="1.0" encoding="UTF-8"?>
02 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN">
03 <html xmlns="http://www.w3.org/1999/xhtml"
04       xmlns:xform="http://www.w3.org/2001/08/xforms"
05       xmlns:pay="http://commerce.example.com/payment"
06       xml:lang="en">
org.xml.sax.SAXException: Stopping after fatal error: White space is
required between the public identifier and the system identifier.

[ca] Omitting the system identifier was permitted in SGML, but is not
allowed in XML.

2) So I changed line 2 as follows (after looking at some other xhtml
documents!):
01 <?xml version="1.0" encoding="UTF-8"?>
02 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN"
"http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">
03 <html xmlns="http://www.w3.org/1999/xhtml"
04       xmlns:xform="http://www.w3.org/2001/08/xforms"
05       xmlns:pay="http://commerce.example.com/payment"
06       xml:lang="en">
This allowed me to go a little further, but now I got the following error
when I hit the <xform:xform> tag:
org.xml.sax.SAXParseException: Element type "xform:xform" must be declared.

[ca] DTD validation is not namespace aware, so the xmlns:* namespace/prefix
bindings look like normal attributes.  xform:xform is not a defined
attribute in the standard xhtml.dtd.


3) So I added the two lines shown below (#7 & #8) to tell Xerces where to
find the xforms schema?
01 <?xml version="1.0" encoding="UTF-8"?>
02 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN"
"http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">
03 <html xmlns="http://www.w3.org/1999/xhtml"
04       xmlns:xform="http://www.w3.org/2001/08/xforms"
05       xmlns:pay="http://commerce.example.com/payment"
06       xml:lang="en"
07       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
08       xsi:schemaLocation="http://www.w3.org/2001/08/xforms xforms.xsd">
Here xforms.xsd is the xforms schema from appendix A of the spec. Anyway now
I am getting the following error when Xerces tries to parse xforms.xsd:
org.xml.sax.SAXParseException: Schema error: prefix : [xml] cannot be
resolved to a URI.
Where do I go from here? Also why did the changes #1 and #2 above fix the
initial errors?
Thanks for your help.

[ca] Schema validation occurs after DTD validation, since you still have a
document type declaration, Xerces (and any other processor) will still try
to DTD validate before schema validating.  If you want to schema validate
without DTD validation, you will need to remove the document type
declaration.

If you really want to DTD validate against the xhtml.dtd, you can augment
the external declaration with an internal subset (maybe not for the newbie).

01 <?xml version="1.0" encoding="UTF-8"?>
02 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN"
"http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd"
[
<!ATTLIST html
   xmlns:xform CDATA #IMPLIED
   xmlns:pay CDATA #IMPLIED
   xml:lang CDATA #IMPLIED
   xmlns:xml CDATA "http://www.w3.org/1999/xml" #FIXED
   xmlns:xsi CDATA #IMPLIED
   xmlns:schemaLocation CDATA #IMPLIED
]
>
03 <html xmlns="http://www.w3.org/1999/xhtml"
04       xmlns:xform="http://www.w3.org/2001/08/xforms"
05       xmlns:pay="http://commerce.example.com/payment"
06       xml:lang="en"
07       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
08       xsi:schemaLocation="http://www.w3.org/2001/08/xforms xforms.xsd">

However, you would have to add definitions for any non-XHTML attribute and
element that you use.

Received on Thursday, 29 November 2001 23:58:28 UTC