Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Namespaces and DTD: attribute "xmlns: ..." must be declared

Status
Not open for further replies.

gsch74

Programmer
Nov 20, 2001
1
GB
Hello,

I have the following XML file (snippet) and the corresponding DTD.
Please note that I want to use namespaces in the XML file:
-----------------------------------------------------------

XML file:

<?xml version=&quot;1.0&quot; standalone=&quot;no&quot;?>
<!DOCTYPE Skat:Turnier SYSTEM &quot;F:\development\xml_projekt\SkatTurnier.DTD&quot;>


<Skat:Turnier xmlns:Skat=&quot; xmlns=&quot;gsch.default/&quot;
AnzahlRunden=&quot;3&quot;>

[...]

-------------------------------------------------------------

Corresponding DTD:

<!ELEMENT Skat:Turnier (Skat:Datum?,
Skat:SpielOrt?,
Skat:Spieler*)>
<!ATTLIST Skat:Turnier AnzahlRunden CDATA #REQUIRED>

[...]

-------------------------------------------------------------
As long as I do not use a validating parser all works fine, and the SAX callback methods startElement() and endElement() indicate that namespace:element is handled correctly.

However, once I turn on validation, the parser throws the following error message, complaining that the &quot;xmlns:...&quot; attribute has not been declared for element Skat:Turnier.


XML file being parsed: F:\development\xml_projekt\skat3110.xml


* setDocumentLocator() was called.
Parsing started....
**Parsing-Error**
Line: 5
URI: file:/f:/development/xml_projekt/skat3110.xml
Message: Attribute &quot;xmlns:Skat&quot; must be declared for element type &quot;Skat:Turnier&quot;.


I know there are some limitations/restrictions concerning DTD and namespaces. Can anyone tell me where my problem is? This is the code snippet that turns on validation.
The parser is Xerces 1.4.3.

try {

XMLReader parser =
XMLReaderFactory.createXMLReader(
&quot;org.apache.xerces.parsers.SAXParser&quot;);

parser.setContentHandler(contentHandler);
parser.setErrorHandler(errorHandler);

// turn on validation
parser.setFeature(&quot; true );
parser.parse(uri);

}

Any help is really appreciated.

Thanks,

Gunnar Schmitz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top