[xml] Whitespace problem with external DTD validation

Date view Thread view Subject view Author view

From: Bill Kendrick (William.Kendrick@wcom.com)
Date: Mon Oct 09 2000 - 19:01:34 EDT


I'm trying to use libxml to simply validate XML documents
based on an external DTD.

(The program is a server written in C... it loads the
necessary DTD into memory, then sits and listens to a socket
for XML documents to come in. When they do, it checks them
and passes them off to another server if they are valid.)

Pretty simple! HOWEVER, there seems to be an issue with
libxml and whitespace...

Say I have the following simply DTD:

--------------------------
<!ELEMENT List (Item)+>
<!ELEMENT Item (#PCDATA)>
--------------------------

I've written a program that reads in a DTD:

  ...
  dtd = xmlParseDTD(NULL, "test.dtd");
  ...

reads in an XML document:

  ...
  doc = xmlParseFile("test.xml");
  ...

and then reports whether the XML is valid,
when compared to the DTD:

  ...
  /* (set up xmlValidCtxt for error reporting when validating) */
  vctxt.userData = stderr;
  vctxt.error = (xmlValidityErrorFunc) fprintf;
  vctxt.warning = (xmlValidityWarningFunc) fprintf;

  xmlDoValidityCheckingDefaultValue = 1;
  
  if (xmlValidateDtd(&vctxt, doc, dtd))
    printf("HORRAY! VALID!\n");
  else
    printf("OOPS! INVALID!\n");
  ...

When the XML document ("test.xml") looks like this,
I get the "HORRAY! VALID!" message:

-------------------------------------------------------------------------
<?xml version="1.0"?>
<!DOCTYPE List>
<List><Item>Chocolate</Item><Item>Music</Item><Item>Surfing</Item></List>
-------------------------------------------------------------------------

But when I do something (that I consider quite reasonable! :) ) and
place some newlines and perhaps indentation in the XML document, I get
errors (see below):

-------------------------------------------------------------------------
<?xml version="1.0"?>
<!DOCTYPE List>
<List>
  <Item>Chocolate</Item>
  <Item>Music</Item>
  <Item>Surfing</Item>
</List>
-------------------------------------------------------------------------

Here's what xmlValidateDtd() reports (to stderr via the vctxt I gave it):

---------------------------------------------------------------
Element List content doesn't follow the Dtd
Expecting (Item)+, got (CDATA Item CDATA Item CDATA Item CDATA)
---------------------------------------------------------------

I even tried the lame solution of sticking "CDATA"'s in the DTD to
work around this, but the DTD parser doesn't like them. :)

I assume this is a bug. Will there be a new version available
soon? If not, can someone recommend a simple XML validator
that supports use of external DTD's? (We need to get this working
VERY SOON!)

-bill!
William.Kendrick@wcom.com
ext 6218

----
Message from the list xml@rpmfind.net
Archived at : http://xmlsoft.org/messages/
to unsubscribe: echo "unsubscribe xml" | mail  majordomo@rpmfind.net


Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Mon Oct 09 2000 - 19:43:17 EDT