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 cyril vidal <cy...@wanadoo.fr> on 2003/08/06 11:55:00 UTC

validation against DTD

Dear all,

I would like to use Xerces in order to validate a very simple document against a DTD:

Here's my XML document to be validated:
<?xml version="1.0" encoding="iso-8859-1"?>

<!DOCTYPE CatalogueLivres
   [
    <!ELEMENT CatalogueLivres (#PCDATA,X,Y)>
    <!ELEMENT X EMPTY>
   <!ELEMENT Y EMPTY>
    ]>
   <CatalogueLivres>
   toto
   <X/>
   <Y/>
   </CatalogueLivres> 

So, CatalogueLivres is supposed to contain both PCDATA and empty elements X and Y and  it seems to be the case...

But during validation, i receive the following error message:
[FATAL Error] CatalogueLivres.xml:5:38: Déclaration of element "CatalogueLivres" must contain either a character ')' (??) or an element type.

When i change the doctype so that CatalogueLivres contains only PCDATA or elements, it runs well...

Could someone explain me where I am wrong, please?
Thanks in advance,
Cyril.

entity reference

Posted by cyril vidal <cy...@wanadoo.fr>.
Dear all,

I would like to parse a xml document and serialize it with entity references
not replaced...

 I've seen in the xerces' doc that by defautl, feature
"http://apache.org/xml/features/dom/create-entity-ref-nodes" is set to true,
and so prevent the entity reference to be replaced by their value.

I've got the following code:

1°) parse the xml document with xerces

// Parser import
import org.apache.xerces.parsers.DOMParser;

...
 DOMParser parser = new DOMParser();
 parser.parse(xmlDocument);
 Document doc = parser.getDocument();
  ...

2°) serialize the doc
     ...
 switch (node.getNodeType()) {
      ...
       case Node.ENTITY_REFERENCE_NODE:
                writer.write("&" + node.getNodeName() + ";");
                break;
    ...
}

I expect to obtain an entity reference in the serialized result (since
xerces during parsing has not replaced them by their value, and the
serialization process keeps those entity references), but actually it's not
the case...

What am I missing here?
Thanks in advance for your responses,
Cyril.



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


Re: validation against DTD

Posted by cyril vidal <cy...@wanadoo.fr>.
Thanks Volker!
Indeed you're right, my DTD was wrong.
http://www.w3.org/TR/REC-xml#NT-Mixed

I should not trust Wrox books (or french translations, I don't know...) from
which the example was extracted..

By the way, could you explain me please the difference between
xercesImpl.jar and xml-apis.jar.

My self experience:


import org.apache.xerces.parsers.DOMParser;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import java.io.IOException;

public class DOMParserDemo2 {

    public static void main (String args[]){
        DOMParser parser = new DOMParser();
        Document doc = null;
        try {
           parser.parse("CatalogueLivres.xml");
           doc = parser.getDocument();
        } catch (IOException ie){
           System.out.println("Could not read file.");
        } catch (SAXException e) {
           System.out.print("Could not create Document: ");
           System.out.println(e.getMessage());
        }

           }
}

will compile well with xercesImpl.jar in classpath but will throw an
exception at runtime:
java.lang.NoClassDefFoundError: org/w3c/dom/range/DocumentRange

All compiles and runs well with xml-apis.jar on my classpath.

why this happens?
I would be very grateful if you may shed light on this topic..

Regards,
Cyril.
----- Original Message -----
From: "Volker Witzel" <vo...@schenker.com>
To: <xe...@xml.apache.org>
Sent: Wednesday, August 06, 2003 1:15 PM
Subject: Re: validation against DTD


> Dear Cyril,
>
> the DTD is wrong. AFAIK mixed content is only possible with a choice,
> thus the DTD should look like:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE CatalogueLivres [
> <!ELEMENT CatalogueLivres (#PCDATA | X | Y)*>
> <!ELEMENT X EMPTY>
> <!ELEMENT Y EMPTY>
> ]>
> <CatalogueLivres>
>     toto
>     <X/>
> <Y/>
> </CatalogueLivres>
>
>
> BTW: I have never understood, where mixed content could be unavoidable
> and/or useful. So, are you sure you want it that way?
>
> Regards,
> Volker.
>
> cyril vidal wrote:
>
> > Dear all,
> >
> > I would like to use Xerces in order to validate a very simple document
> > against a DTD:
> >
> > Here's my XML document to be validated:
> > <?xml version="1.0" encoding="iso-8859-1"?>
> >
> > <!DOCTYPE CatalogueLivres
> >    [
> >     <!ELEMENT CatalogueLivres (#PCDATA,X,Y)>
> >     <!ELEMENT X EMPTY>
> >    <!ELEMENT Y EMPTY>
> >     ]>
> >    <CatalogueLivres>
> >    toto
> >    <X/>
> >    <Y/>
> >    </CatalogueLivres>
> >
> > So, CatalogueLivres is supposed to contain both PCDATA and empty
> > elements X and Y and  it seems to be the case...
> >
> > But during validation, i receive the following error message:
> > [FATAL Error] CatalogueLivres.xml:5:38: Déclaration of element
> > "CatalogueLivres" must contain either a character ')' (??) or an element
> > type.
> >
> > When i change the doctype so that CatalogueLivres contains only PCDATA
> > or elements, it runs well...
> >
> > Could someone explain me where I am wrong, please?
> > Thanks in advance,
> > Cyril.
>
>
>
>
> ---------------------------------------------------------------------
> 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: validation against DTD

Posted by Volker Witzel <vo...@schenker.com>.
Dear Cyril,

the DTD is wrong. AFAIK mixed content is only possible with a choice, 
thus the DTD should look like:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE CatalogueLivres [
	<!ELEMENT CatalogueLivres (#PCDATA | X | Y)*>
	<!ELEMENT X EMPTY>
	<!ELEMENT Y EMPTY>
]>
<CatalogueLivres>
    toto
    <X/>
	<Y/>
</CatalogueLivres>


BTW: I have never understood, where mixed content could be unavoidable 
and/or useful. So, are you sure you want it that way?

Regards,
Volker.

cyril vidal wrote:

> Dear all,
>  
> I would like to use Xerces in order to validate a very simple document 
> against a DTD:
>  
> Here's my XML document to be validated:
> <?xml version="1.0" encoding="iso-8859-1"?>
>  
> <!DOCTYPE CatalogueLivres
>    [
>     <!ELEMENT CatalogueLivres (#PCDATA,X,Y)>
>     <!ELEMENT X EMPTY>
>    <!ELEMENT Y EMPTY>
>     ]>
>    <CatalogueLivres>
>    toto
>    <X/>
>    <Y/>
>    </CatalogueLivres>
>  
> So, CatalogueLivres is supposed to contain both PCDATA and empty 
> elements X and Y and  it seems to be the case...
>  
> But during validation, i receive the following error message:
> [FATAL Error] CatalogueLivres.xml:5:38: Déclaration of element 
> "CatalogueLivres" must contain either a character ')' (??) or an element 
> type.
>  
> When i change the doctype so that CatalogueLivres contains only PCDATA 
> or elements, it runs well...
>  
> Could someone explain me where I am wrong, please?
> Thanks in advance,
> Cyril.




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