Re: validate XML with DTD and Xerces: Non-whitespace characters
- From: Peter Flynn <peter.nosp@xxxxxxxxxxxxx>
- Date: Sun, 25 Sep 2005 15:16:49 +0100
Georg J. Stach wrote:
> Hi,
>
> as mentioned above I'd like to validate a simple XML-document with a
> simple DTD.
> For this, I use Java and Xerces.
Don't. If you want standalone validation with a DTD, use a standalone
validating parser like onsgmls or rxp.
> But, when I have tags of this form:
>
> <tag>some characters in here</tag>
>
> Xerces always complains with:
> org.xml.sax.SAXParseException: s4s-elt-character: Non-whitespace
> characters are not allowed in schema elements other than 'xs:appinfo' and
> 'xs:documentation'. Saw 'some characters in here'.
>
> The XML-doc is this:
>
> <?xml version="1.0" encoding="ISO-8859-1" ?>
> <!DOCTYPE durchwahlnummer SYSTEM "mydtd.dtd">
> <mytag>123456</mytag>
>
> ------------
>
> The DTD mydtd.dtd that:
>
> <!ELEMENT mytag (#PCDATA)>
The name you declare in the Document Type Declaration must be the
same as the name of the root element type. Change your XML file to
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE mytag SYSTEM "mydtd.dtd">
<mytag>123456</mytag>
(or change the DTD to declare durchwahlnummer instead).
> As you can see, the mytag-tag is explicitly declared as PCDATA type, so
> the error with "non-Whitespace characters" should actually not occur.
Your validator isn't giving you the whole story. If I test your original
with onsgmls, I get a much more explicit report:
> $ onsgmls -wxml -s -E 5000 /usr/share/sgml/xml.dcl test.xml
> onsgmls:/usr/share/sgml/xml.dcl:1:W: SGML declaration was not implied
> onsgmls:test.xml:2:44:E: DTD did not contain element declaration for
document type name
> onsgmls:test.xml:3:6:E: document type does not allow element "mytag" here
> onsgmls:test.xml:3:22:E: no document element
> SGML validation exited abnormally with code 1 at Sun Sep 25 15:14:21
> $
///Peter
.
- Follow-Ups:
- Re: validate XML with DTD and Xerces: Non-whitespace characters
- From: Georg J. Stach
- Re: validate XML with DTD and Xerces: Non-whitespace characters
- References:
- validate XML with DTD and Xerces: Non-whitespace characters
- From: Georg J. Stach
- validate XML with DTD and Xerces: Non-whitespace characters
- Prev by Date: XSL output method to XML & JavaScript problem
- Next by Date: Re: XSL output method to XML & JavaScript problem
- Previous by thread: Re: validate XML with DTD and Xerces: Non-whitespace characters
- Next by thread: Re: validate XML with DTD and Xerces: Non-whitespace characters
- Index(es):
Relevant Pages
|