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 Julian Templeman <ju...@groucho.demon.co.uk> on 2001/03/31 19:01:02 UTC

Using Namespaces and DTDs...

A question for the collected wisdom of the list...

Can anyone tell me whether it's possible to use a DTD with a document
that uses namespaces when you're using Xerces-J as the parser?

I know that DTDs and namespaces don't really mix, and I know the
suggested work-around of putting the xmlns: in the ATTLIST as a #FIXED
attribute. The problem is that it doesn't work with Xerces, which
throws a parser exception telling me that the root element 'must be
defined'.

Does anyone know whether this can be done?

Thanks,

julian
Templeman Consulting Limited
London and North Wales
http://www.templeman-consulting.co.uk

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


Re: Using Namespaces and DTDs...

Posted by Hilary Bannister <hi...@cwcom.net>.
The only thing I can spot which made a difference when using your example is
that :

<!ELEMENT test:complex-structure (EMPTY)>

should be:

<!ELEMENT test:complex-structure EMPTY>

but I got a different SAX parse error pointing this out.  Once this was
corrected it parsed happily with the namespace.

I use the following set of features, but the first two are the default
values anyway aren't they?
         parser.setFeature("http://xml.org/sax/features/namespaces",true);

parser.setFeature("http://xml.org/sax/features/namespace-prefixes",false);
         parser.setFeature("http://xml.org/sax/features/validation", true);

My only other question is, is your dtd as simple as below or are there more
element definitions?  If so there may be another syntax problem which is
causing the SAX not to see the test:top-element declaration.  I have had
many a problem with incorrect dtds and the errors the SAX parser produces
may not highlight the actual problem.  My client's problem is generating
syntactically correct MIXED declarations.

Sorry I can be of no more help.

Hilary

----- Original Message -----
From: Julian Templeman <ju...@groucho.demon.co.uk>
To: <xe...@xml.apache.org>; Hilary Bannister
<hi...@cwcom.net>
Sent: 03 April 2001 20:02
Subject: Re: Using Namespaces and DTDs...


Hilary said:

>An simple example of a DTD (called all-tests.dtd) would be:
>
><!ELEMENT test:top-element
> (test:simple-structure | test:complex-structure | test:complex-structure2
|
>test:complex-structure3 | test:complex-structure4)+>
><!ATTLIST test:top-element
>      xmlns:test CDATA #FIXED "http://deltaxml.com/docs/dtds/test/test-co1>
>....
>
>and the xml document would be:
>
><?xml version="1.0"?>
><!DOCTYPE test:top-element SYSTEM "all-tests.dtd">
><test:top-element ><test:complex-structure/>
></test:top-element>

OK... that's how I understood it ought to work. So I took the example
and made up an XML file ike this:

<?xml version="1.0"?>
<!DOCTYPE test:top-element SYSTEM "test1.dtd">
<test:top-element
xmlns:test="http://deltaxml.com/docs/dtds/test/test-co1">
<test:complex-structure/>
</test:top-element>

And a DTD like this:

<!ELEMENT test:top-element (test:complex-structure)+>
<!ATTLIST test:top-element
      xmlns:test CDATA #FIXED
"http://deltaxml.com/docs/dtds/test/test-co1">
<!ELEMENT test:complex-structure (EMPTY)>

The Java code creates a SAX parser, turns validation and namespace
awareness on, and then tries to parse the file. The result is the same
as before, with a parser error in line 3 of the XML: "test:top-element
must be declared"

If I turn validation off then the problem doesn't occur, but then
neither does validation, so it's hardly useful :-)

Any hints as to what is going on will be gratefully received!

julian

Templeman Consulting Limited
London and North Wales
http://www.templeman-consulting.co.uk

---------------------------------------------------------------------
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


Re: Using Namespaces and DTDs...

Posted by Julian Templeman <ju...@groucho.demon.co.uk>.
Hilary said:

>An simple example of a DTD (called all-tests.dtd) would be:
>
><!ELEMENT test:top-element
> (test:simple-structure | test:complex-structure | test:complex-structure2 |
>test:complex-structure3 | test:complex-structure4)+>
><!ATTLIST test:top-element
>      xmlns:test CDATA #FIXED "http://deltaxml.com/docs/dtds/test/test-co1>
>....
>
>and the xml document would be:
>
><?xml version="1.0"?>
><!DOCTYPE test:top-element SYSTEM "all-tests.dtd">
><test:top-element ><test:complex-structure/>
></test:top-element>

OK... that's how I understood it ought to work. So I took the example
and made up an XML file ike this:

<?xml version="1.0"?>
<!DOCTYPE test:top-element SYSTEM "test1.dtd">
<test:top-element
xmlns:test="http://deltaxml.com/docs/dtds/test/test-co1">
<test:complex-structure/>
</test:top-element>

And a DTD like this:

<!ELEMENT test:top-element (test:complex-structure)+>
<!ATTLIST test:top-element
      xmlns:test CDATA #FIXED
"http://deltaxml.com/docs/dtds/test/test-co1">
<!ELEMENT test:complex-structure (EMPTY)>

The Java code creates a SAX parser, turns validation and namespace
awareness on, and then tries to parse the file. The result is the same
as before, with a parser error in line 3 of the XML: "test:top-element
must be declared"

If I turn validation off then the problem doesn't occur, but then
neither does validation, so it's hardly useful :-)

Any hints as to what is going on will be gratefully received!

julian

Templeman Consulting Limited
London and North Wales
http://www.templeman-consulting.co.uk

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


Re: Using Namespaces and DTDs...

Posted by Hilary Bannister <hi...@cwcom.net>.
Yes it is possible to use namespaces within a DTD though it is not quite the
same as for schemas.

Xerces 1.2.3 and beyond understand namespaces though this can be switched
off by setting the appropriate feature.

         parser.setFeature("http://xml.org/sax/features/namespaces",false);

Yes namespaces do work with Xerces as our software uses this feature
extensively.

An simple example of a DTD (called all-tests.dtd) would be:

<!ELEMENT test:top-element
 (test:simple-structure | test:complex-structure | test:complex-structure2 |
test:complex-structure3 | test:complex-structure4)+>
<!ATTLIST test:top-element
      xmlns:test CDATA #FIXED "http://deltaxml.com/docs/dtds/test/test-co1>
....

and the xml document would be:

<?xml version="1.0"?>
<!DOCTYPE test:top-element SYSTEM "all-tests.dtd">
<test:top-element ><test:complex-structure/>
</test:top-element>

Internet Explorer does not like displaying the xml file but Xerces can parse
it quite happily.  The DTD must contain the prefix of the namespace.

Hope this helps.

Hilary

----- Original Message -----
From: Julian Templeman <ju...@groucho.demon.co.uk>
To: <xe...@xml.apache.org>
Sent: 31 March 2001 18:01
Subject: Using Namespaces and DTDs...


A question for the collected wisdom of the list...

Can anyone tell me whether it's possible to use a DTD with a document
that uses namespaces when you're using Xerces-J as the parser?

I know that DTDs and namespaces don't really mix, and I know the
suggested work-around of putting the xmlns: in the ATTLIST as a #FIXED
attribute. The problem is that it doesn't work with Xerces, which
throws a parser exception telling me that the root element 'must be
defined'.

Does anyone know whether this can be done?

Thanks,

julian
Templeman Consulting Limited
London and North Wales
http://www.templeman-consulting.co.uk

---------------------------------------------------------------------
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