Re: validate XML with DTD and Xerces: Non-whitespace characters



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

.



Relevant Pages

  • validating xml against DTD
    ... I am using the following code to validate an xml file ... against a DTD. ... I force the requirement to declare the DTD in the XML ... Private Function validate() As Boolean ...
    (microsoft.public.dotnet.languages.vb)
  • Re: standalone validating XML parser for Solaris?
    ... the unix command line to validate large XML files against an XML DTD. ... Older versions only parse but dont validate. ... More recent versions can validate against DTD or Schema. ...
    (comp.text.xml)
  • Re: validateris seeing errors in the name microsoft themes
    ... Change to HTML view and change there if you want it to validate. ... Microsoft MVP - Frontpage. ... > the document type you are using does not support that ... > supported in the document type you are using, ...
    (microsoft.public.frontpage.programming)
  • Problem with DTD declaration
    ... I have a DTD. ... If I declare it at the top of my XML file, ... If I remove - or comment out - the DTD declaration line the transform ...
    (comp.text.xml)
  • Re: Validating against a higher standard
    ... Most people don't know how to read error messages, especially when the messages are cryptic. ... don't actually read the DTD, still less make use of it. ... Besides, it's pure theory, since on the Web as of now, a very large amount of pages that declare some doctype doesn't actually comply with it. ... Using XHTML served as some flavor of XML might be different, but even then, browsers are currently interested in well-formedness at most, and that doesn't depend on DTDs. ...
    (comp.infosystems.www.authoring.html)