You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Ian Campbell <Ia...@thomson.com.au> on 2000/10/27 01:56:35 UTC
XML Conformance Issue (XJ 1.2)
I think there may be a minor XML conformance issue with Xerces-J 1.2 .
It recognises parameter entities inside system identifiers but if you
strictly follow the XML spec this is not allowed...
eg. this type of thing works:
<!-- Call default element names fragment -->
<!ENTITY % DefaultNames.frag
PUBLIC "-//TLRGAP//ENTITY Default Element Names//EN"
"%DefaultNames.sysid;" >
%DefaultNames.frag;
Productions cut from XML spec:
[70] EntityDecl ::= GEDecl | PEDecl
[72] PEDecl ::= '<!ENTITY' S '%' S Name S PEDef S? '>'
[74] PEDef ::= EntityValue | ExternalID
[75] ExternalID ::= 'SYSTEM' S SystemLiteral | 'PUBLIC' S PubidLiteral S
SystemLiteral
SystemLiteral ::= ('"' [^"]* '"') | ("'" [^']* "'")
As you can see you can only end up at a SystemLiteral which is strictly
non-terminals.
If I am reading it right ( [^"]* ) then the string "%DefaultNames.sysid;"
*should* be accepted but not recognised as a PE and not resolved. (Xerces-J
does both)
If you remove the quotes in the above example then Xerces-J 1.2 correctly
rejects.
--
Ian
=====================================================================
WARNING -This e-mail, including any attachments, is for the
personal use of the recipient(s) only.
Republication and re-dissemination, including posting to news
groups or web pages, is strictly prohibited without the express
prior consent of
Thomson Legal & Regulatory Group Asia Pacific Ltd
ACN 058 914 668
=====================================================================
Re: Bug in xerces-j 1.2.1, validation doesn't work
Posted by jeff <jl...@houseofdistraction.com>.
Thank you very much.
Elena Litani wrote:
>
> Hi, Jeff,
>
> A ContentHandler interface handles parsing events.
> To see the errors, you have to implement and register
> an ErrorHandler.
>
> By default, the parser will only stop if document is not well-formed.
> Since validation errors are not fatal, the parser will continue.
>
> Good Luck,
> Elena
>
> jeff wrote:
> >
> > Here's my test code. Maybe I'm doing something wrong but it seems like
> > this should barf on the second <bar/> or at least on the <bletch/>.
> > Instead I get the following output:
> >
> > ---------------------------------------------------
> > <stdout>
> > ---------------------------------------------------
> > 4: START foo
> > 5: START bar
> > 5: END bar
> > 6: START bar
> > 6: END bar
> > 7: START bletch
> > 7: END bletch
> > 8: END foo
> > java.lang.Exception: There was no exception during the parse!
> > at ValidationTest.main(ValidationTest.java:16)
> > Exception in thread "main"
> >
> > ---------------------------------------------------
> > validation-test.dtd
> > ---------------------------------------------------
> > <?xml version="1.0" encoding="UTF-8"?>
> >
> > <!ELEMENT foo (bar)>
> > <!ELEMENT bar EMPTY>
> > <!ELEMENT bletch EMPTY>
> >
> > ---------------------------------------------------
> > validation-test.xml
> > ---------------------------------------------------
> > <?xml version="1.0" encoding="UTF-8"?>
> > <!DOCTYPE Invoice SYSTEM "validation-test.dtd">
> >
> > <foo>
> > <bar/>
> > <bar/>
> > <bletch/>
> > </foo>
> >
> > ---------------------------------------------------
> > ValidationTest.java
> > ---------------------------------------------------
> > import java.io.*;
> > import org.xml.sax.*;
> > import org.apache.xerces.parsers.SAXParser;
> >
> > public class ValidationTest implements ContentHandler
> > {
> > Locator locator = null;
> > public static void main( String args[] ) throws Throwable
> > {
> > XMLReader reader = new SAXParser();
> > ContentHandler handler = new ValidationTest();
> > reader.setContentHandler( handler );
> > reader.setFeature( "http://xml.org/sax/features/validation", true );
> > reader.setFeature( "http://apache.org/xml/features/validation/dynamic", true );
> > reader.parse( new InputSource( new FileInputStream( "validation-test.xml" ) ) );
> > throw new Exception( "There was no exception during the parse!" );
> > }
> >
> > public void startElement( String namespaceURI, String localName, String qName, Attributes atts ) throws SAXException
> > {
> > System.out.println( String.valueOf( locator.getLineNumber() ) + ": START " + qName );
> > }
> >
> > public void endElement( String namespaceURI, String localName, String qName ) throws SAXException
> > {
> > System.out.println( String.valueOf( locator.getLineNumber() ) + ": END " + qName );
> > }
> >
> > public void setDocumentLocator( Locator locator )
> > {
> > this.locator = locator;
> > }
> >
> > public void characters( char ch[], int start, int length ) throws SAXException { }
> > public void ignorableWhitespace( char ch[], int start, int length ) throws SAXException { }
> > public void processingInstruction( String target, String datap) throws SAXException { }
> > public void skippedEntity( String name ) throws SAXException { }
> > public void endPrefixMapping( String prefix ) throws SAXException { }
> > public void startPrefixMapping( String prefix, String uri ) throws SAXException { }
> > public void endDocument() throws SAXException { }
> > public void startDocument() throws SAXException { }
> > }
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
> > For additional commands, e-mail: xerces-j-dev-help@xml.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-dev-help@xml.apache.org
Re: Bug in xerces-j 1.2.1, validation doesn't work
Posted by Elena Litani <hl...@jtcsv.com>.
Hi, Jeff,
A ContentHandler interface handles parsing events.
To see the errors, you have to implement and register
an ErrorHandler.
By default, the parser will only stop if document is not well-formed.
Since validation errors are not fatal, the parser will continue.
Good Luck,
Elena
jeff wrote:
>
> Here's my test code. Maybe I'm doing something wrong but it seems like
> this should barf on the second <bar/> or at least on the <bletch/>.
> Instead I get the following output:
>
> ---------------------------------------------------
> <stdout>
> ---------------------------------------------------
> 4: START foo
> 5: START bar
> 5: END bar
> 6: START bar
> 6: END bar
> 7: START bletch
> 7: END bletch
> 8: END foo
> java.lang.Exception: There was no exception during the parse!
> at ValidationTest.main(ValidationTest.java:16)
> Exception in thread "main"
>
> ---------------------------------------------------
> validation-test.dtd
> ---------------------------------------------------
> <?xml version="1.0" encoding="UTF-8"?>
>
> <!ELEMENT foo (bar)>
> <!ELEMENT bar EMPTY>
> <!ELEMENT bletch EMPTY>
>
> ---------------------------------------------------
> validation-test.xml
> ---------------------------------------------------
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE Invoice SYSTEM "validation-test.dtd">
>
> <foo>
> <bar/>
> <bar/>
> <bletch/>
> </foo>
>
> ---------------------------------------------------
> ValidationTest.java
> ---------------------------------------------------
> import java.io.*;
> import org.xml.sax.*;
> import org.apache.xerces.parsers.SAXParser;
>
> public class ValidationTest implements ContentHandler
> {
> Locator locator = null;
> public static void main( String args[] ) throws Throwable
> {
> XMLReader reader = new SAXParser();
> ContentHandler handler = new ValidationTest();
> reader.setContentHandler( handler );
> reader.setFeature( "http://xml.org/sax/features/validation", true );
> reader.setFeature( "http://apache.org/xml/features/validation/dynamic", true );
> reader.parse( new InputSource( new FileInputStream( "validation-test.xml" ) ) );
> throw new Exception( "There was no exception during the parse!" );
> }
>
> public void startElement( String namespaceURI, String localName, String qName, Attributes atts ) throws SAXException
> {
> System.out.println( String.valueOf( locator.getLineNumber() ) + ": START " + qName );
> }
>
> public void endElement( String namespaceURI, String localName, String qName ) throws SAXException
> {
> System.out.println( String.valueOf( locator.getLineNumber() ) + ": END " + qName );
> }
>
> public void setDocumentLocator( Locator locator )
> {
> this.locator = locator;
> }
>
> public void characters( char ch[], int start, int length ) throws SAXException { }
> public void ignorableWhitespace( char ch[], int start, int length ) throws SAXException { }
> public void processingInstruction( String target, String datap) throws SAXException { }
> public void skippedEntity( String name ) throws SAXException { }
> public void endPrefixMapping( String prefix ) throws SAXException { }
> public void startPrefixMapping( String prefix, String uri ) throws SAXException { }
> public void endDocument() throws SAXException { }
> public void startDocument() throws SAXException { }
> }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-dev-help@xml.apache.org
Bug in xerces-j 1.2.1, validation doesn't work
Posted by jeff <jl...@houseofdistraction.com>.
Here's my test code. Maybe I'm doing something wrong but it seems like
this should barf on the second <bar/> or at least on the <bletch/>.
Instead I get the following output:
---------------------------------------------------
<stdout>
---------------------------------------------------
4: START foo
5: START bar
5: END bar
6: START bar
6: END bar
7: START bletch
7: END bletch
8: END foo
java.lang.Exception: There was no exception during the parse!
at ValidationTest.main(ValidationTest.java:16)
Exception in thread "main"
---------------------------------------------------
validation-test.dtd
---------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT foo (bar)>
<!ELEMENT bar EMPTY>
<!ELEMENT bletch EMPTY>
---------------------------------------------------
validation-test.xml
---------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Invoice SYSTEM "validation-test.dtd">
<foo>
<bar/>
<bar/>
<bletch/>
</foo>
---------------------------------------------------
ValidationTest.java
---------------------------------------------------
import java.io.*;
import org.xml.sax.*;
import org.apache.xerces.parsers.SAXParser;
public class ValidationTest implements ContentHandler
{
Locator locator = null;
public static void main( String args[] ) throws Throwable
{
XMLReader reader = new SAXParser();
ContentHandler handler = new ValidationTest();
reader.setContentHandler( handler );
reader.setFeature( "http://xml.org/sax/features/validation", true );
reader.setFeature( "http://apache.org/xml/features/validation/dynamic", true );
reader.parse( new InputSource( new FileInputStream( "validation-test.xml" ) ) );
throw new Exception( "There was no exception during the parse!" );
}
public void startElement( String namespaceURI, String localName, String qName, Attributes atts ) throws SAXException
{
System.out.println( String.valueOf( locator.getLineNumber() ) + ": START " + qName );
}
public void endElement( String namespaceURI, String localName, String qName ) throws SAXException
{
System.out.println( String.valueOf( locator.getLineNumber() ) + ": END " + qName );
}
public void setDocumentLocator( Locator locator )
{
this.locator = locator;
}
public void characters( char ch[], int start, int length ) throws SAXException { }
public void ignorableWhitespace( char ch[], int start, int length ) throws SAXException { }
public void processingInstruction( String target, String datap) throws SAXException { }
public void skippedEntity( String name ) throws SAXException { }
public void endPrefixMapping( String prefix ) throws SAXException { }
public void startPrefixMapping( String prefix, String uri ) throws SAXException { }
public void endDocument() throws SAXException { }
public void startDocument() throws SAXException { }
}