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 S <st...@cyberspace.org> on 2002/01/13 14:07:21 UTC

writing a good error handler

Hi
now that I could validate an xml against an xsd,
I need a better error handler that can point out
the line number in the xml where the error is, in addition to the error.
is this possible? The in-memory representation of an xml doesnt have lines,
so this may not be possible. I am looking for error handling better than
 public void error(SAXParseException ex) {
       System.out.println("[ERROR  ]: "+ex.getMessage());
         Parser.docValid = false;
 }   



thanks, st.

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


RE: writing a good error handler

Posted by Mark Lines-Davies <ml...@spd.sonybpe.com>.
S wrote:

> 2. Under xerces 2, I am getting the following error:
> Exception in thread "main" org.xml.sax.SAXNotRecognizedException:
> http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation

I had the same problem (I think). Searching through the archives I found
that a bug had been reported just before Christmas. Code to fix it was
posted, but I didn't want to rebuild the xerces jar, so I subclassed the
standard class instead (see below). The new class just gets passed into the
DOMParser constructor.

regards

Mark Lines-Davies

public class MyParserConfiguration extends StandardParserConfiguration{

  protected void checkProperty(String propertyId) throws
XMLConfigurationException {
    if (propertyId.startsWith(Constants.XERCES_PROPERTY_PREFIX)) {
      String property =
propertyId.substring(Constants.XERCES_PROPERTY_PREFIX.length());
      if (property.equals(Constants.DTD_SCANNER_PROPERTY)) {
        return;
      }
      if (property.equals(Constants.SCHEMA_LOCATION)) {
        return;
      }
      if (property.equals(Constants.SCHEMA_NONS_LOCATION)) {
        return;
      }
    }
    super.checkProperty(propertyId);
  }
}



*************************************************************************
The information contained in this message or any of its
attachments may be privileged and confidential and intended 
for the exclusive use of the addressee. If you are not the
addressee any disclosure, reproduction, distribution or other
dissemination or use of this communication is strictly prohibited
*************************************************************************

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


Re: writing a good error handler

Posted by S <st...@cyberspace.org>.
Quoting Mark Lines-Davies (mld@spd.sonybpe.com):
> Hi John K, S
> 
> I tried something similar, but the line and column numbers are always -1.
> 
> Do I need to do something extra to make this work? I'm using xerces 2.



1. Under xerces 1.4.4, I am getting incorrect line numbers.
What are your experiences on this?

2. Under xerces 2, I am getting the following error:
Exception in thread "main" org.xml.sax.SAXNotRecognizedException:
http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation    

I have xercesImpl.jar and xmlParserAPIs.jar in the classpath.



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


Re: writing a good error handler

Posted by John Keyes <jo...@yahoo.com>.
Hi Mark,

I haven't tried this in Xerces 2 or using in memory XML.
Using 1.4.3 and XML files it behaves correctly.  If I
get a chance I will try with Xerces 2 and post the result.

-John K

Mark Lines-Davies wrote:

> Hi John K, S
> 
> I tried something similar, but the line and column numbers are always -1.
> 
> Do I need to do something extra to make this work? I'm using xerces 2.
> 
> regards
> 
> Mark Lines-Davies
> 
> -----Original Message-----
> From: John Keyes [mailto:johnkeyes@yahoo.com]
> Sent: 13 January 2002 14:06
> To: xerces-j-user@xml.apache.org
> Subject: Re: writing a good error handler
> 
> 
> Hi S,
> 
> The API for org.xml.sax.SAXParseException is:
> 
> [using xerces 1.4.3 jar]
> 
>      public int getColumnNumber();
>      public int getLineNumber();
>      public java.lang.String getPublicId();
>      public java.lang.String getSystemId();
> 
> So if you could write your error method as:
> 
>      StringBuffer message = new StringBuffer();
>      ...
>      public void error(SAXParseException ex) {
> 	message.setLength(0);
>          message.append("[ERROR]:").append(ex.getMessage());
>          message.append(" at line ").append(ex.getLineNumber());
>          message.append(" column ").append(ex.getColumnNumber());
>          System.out.println(message);
>          Parser.docValid = false;
>      }
> 
> -John K
> 
> S wrote:
> 
> 
>>Hi
>>now that I could validate an xml against an xsd,
>>I need a better error handler that can point out
>>the line number in the xml where the error is, in addition to the error.
>>is this possible? The in-memory representation of an xml doesnt have
>>
> lines,
> 
>>so this may not be possible. I am looking for error handling better than
>> public void error(SAXParseException ex) {
>>       System.out.println("[ERROR  ]: "+ex.getMessage());
>>         Parser.docValid = false;
>> }
>>
>>
>>
>>thanks, st.
>>
>>---------------------------------------------------------------------
>>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
> 
> 
> 
> 
> *************************************************************************
> The information contained in this message or any of its
> attachments may be privileged and confidential and intended 
> for the exclusive use of the addressee. If you are not the
> addressee any disclosure, reproduction, distribution or other
> dissemination or use of this communication is strictly prohibited
> *************************************************************************
> 
> ---------------------------------------------------------------------
> 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: ClassCastException in DOMParser

Posted by Mark Lines-Davies <ml...@spd.sonybpe.com>.
The problem appears to be an <xsd:union> element in my XSD. If I take this
out, the problem disappears.

I guess this is a bug...?

regards

Mark Lines-Davies

-----Original Message-----
From: Mark Lines-Davies [mailto:mld@spd.sonybpe.com]
Sent: 14 January 2002 11:42
To: xerces-j-user@xml.apache.org
Subject: ClassCastException in DOMParser


Hello all

I'm getting a ClassCastException in the parse() method at line 270 in
DOMParser. I'm using Xerces 2.

To find out more, I subclassed DOMParser, cut-and-pasted the parse() method
into my subclass, then changed the catch blocks to a single "catch
(Exception)" block. Doing this pointed me to the parse() method at line 572
of StandardParserConfiguration.

I subclassed StandardParserConfiguration to make a temporary version of this
parse method, and removed all the catch blocks. The resulting stack trace is
shown below.

I couldn't see anything in the mailing lists about this, so I thought I'd
ask for help. Help!

regards

Mark Lines-Davies


java.lang.ClassCastException: org.apache.xerces.impl.xs.XSComplexTypeDecl
        at
org.apache.xerces.impl.xs.traversers.XSDSimpleTypeTraverser.findDTVal
idator(XSDSimpleTypeTraverser.java:530)
        at
org.apache.xerces.impl.xs.traversers.XSDSimpleTypeTraverser.traverseS
impleTypeDecl(XSDSimpleTypeTraverser.java:327)
        at
org.apache.xerces.impl.xs.traversers.XSDSimpleTypeTraverser.traverseL
ocal(XSDSimpleTypeTraverser.java:155)
        at
org.apache.xerces.impl.xs.traversers.XSDElementTraverser.traverseName
dElement(XSDElementTraverser.java:328)
        at
org.apache.xerces.impl.xs.traversers.XSDElementTraverser.traverseLoca
l(XSDElementTraverser.java:188)
        at
org.apache.xerces.impl.xs.traversers.XSDHandler.traverseLocalElements
(XSDHandler.java:1174)
        at
org.apache.xerces.impl.xs.traversers.XSDHandler.parseSchema(XSDHandle
r.java:371)
        at
org.apache.xerces.impl.xs.XMLSchemaValidator.parseSchemas(XMLSchemaVa
lidator.java:1699)
        at
org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(XMLSc
hemaValidator.java:1280)
        at
org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(XMLSchemaVa
lidator.java:511)
        at
org.apache.xerces.impl.XMLNamespaceBinder.handleStartElement(XMLNames
paceBinder.java:830)
        at
org.apache.xerces.impl.XMLNamespaceBinder.startElement(XMLNamespaceBi
nder.java:566)
        at
org.apache.xerces.impl.dtd.XMLDTDValidator.startElement(XMLDTDValidat
or.java:786)
        at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElemen
t(XMLDocumentFragmentScannerImpl.java:751)
        at
org.apache.xerces.impl.XMLDocumentScannerImpl$ContentDispatcher.scanR
ootElementHook(XMLDocumentScannerImpl.java:935)
        at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContent
Dispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1514)
        at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(XM
LDocumentFragmentScannerImpl.java:332)
        at
org.apache.xerces.parsers.StandardParserConfiguration.parse(StandardP
arserConfiguration.java:510)
        at
com.sony.antenne.ValidatingParserConfiguration.parse(ValidatingParser
Configuration.java:27)
        at org.apache.xerces.parsers.XMLParser.parse(XMLParser.java:148)
        at com.sony.antenne.ValidatingParser.parse(ValidatingParser.java:58)
        at com.sony.antenne.ValidatingParser.parse(ValidatingParser.java:69)
        at com.sony.antenne.Schema.validate(Schema.java:34)
        at com.sony.antenne.InboundMessage.validate(InboundMessage.java:43)
        at com.sony.antenne.InboundMessage.process(InboundMessage.java:31)



*************************************************************************
The information contained in this message or any of its
attachments may be privileged and confidential and intended
for the exclusive use of the addressee. If you are not the
addressee any disclosure, reproduction, distribution or other
dissemination or use of this communication is strictly prohibited
*************************************************************************

---------------------------------------------------------------------
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


ClassCastException in DOMParser

Posted by Mark Lines-Davies <ml...@spd.sonybpe.com>.
Hello all

I'm getting a ClassCastException in the parse() method at line 270 in
DOMParser. I'm using Xerces 2.

To find out more, I subclassed DOMParser, cut-and-pasted the parse() method
into my subclass, then changed the catch blocks to a single "catch
(Exception)" block. Doing this pointed me to the parse() method at line 572
of StandardParserConfiguration.

I subclassed StandardParserConfiguration to make a temporary version of this
parse method, and removed all the catch blocks. The resulting stack trace is
shown below.

I couldn't see anything in the mailing lists about this, so I thought I'd
ask for help. Help!

regards

Mark Lines-Davies


java.lang.ClassCastException: org.apache.xerces.impl.xs.XSComplexTypeDecl
        at
org.apache.xerces.impl.xs.traversers.XSDSimpleTypeTraverser.findDTVal
idator(XSDSimpleTypeTraverser.java:530)
        at
org.apache.xerces.impl.xs.traversers.XSDSimpleTypeTraverser.traverseS
impleTypeDecl(XSDSimpleTypeTraverser.java:327)
        at
org.apache.xerces.impl.xs.traversers.XSDSimpleTypeTraverser.traverseL
ocal(XSDSimpleTypeTraverser.java:155)
        at
org.apache.xerces.impl.xs.traversers.XSDElementTraverser.traverseName
dElement(XSDElementTraverser.java:328)
        at
org.apache.xerces.impl.xs.traversers.XSDElementTraverser.traverseLoca
l(XSDElementTraverser.java:188)
        at
org.apache.xerces.impl.xs.traversers.XSDHandler.traverseLocalElements
(XSDHandler.java:1174)
        at
org.apache.xerces.impl.xs.traversers.XSDHandler.parseSchema(XSDHandle
r.java:371)
        at
org.apache.xerces.impl.xs.XMLSchemaValidator.parseSchemas(XMLSchemaVa
lidator.java:1699)
        at
org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(XMLSc
hemaValidator.java:1280)
        at
org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(XMLSchemaVa
lidator.java:511)
        at
org.apache.xerces.impl.XMLNamespaceBinder.handleStartElement(XMLNames
paceBinder.java:830)
        at
org.apache.xerces.impl.XMLNamespaceBinder.startElement(XMLNamespaceBi
nder.java:566)
        at
org.apache.xerces.impl.dtd.XMLDTDValidator.startElement(XMLDTDValidat
or.java:786)
        at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElemen
t(XMLDocumentFragmentScannerImpl.java:751)
        at
org.apache.xerces.impl.XMLDocumentScannerImpl$ContentDispatcher.scanR
ootElementHook(XMLDocumentScannerImpl.java:935)
        at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContent
Dispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1514)
        at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(XM
LDocumentFragmentScannerImpl.java:332)
        at
org.apache.xerces.parsers.StandardParserConfiguration.parse(StandardP
arserConfiguration.java:510)
        at
com.sony.antenne.ValidatingParserConfiguration.parse(ValidatingParser
Configuration.java:27)
        at org.apache.xerces.parsers.XMLParser.parse(XMLParser.java:148)
        at com.sony.antenne.ValidatingParser.parse(ValidatingParser.java:58)
        at com.sony.antenne.ValidatingParser.parse(ValidatingParser.java:69)
        at com.sony.antenne.Schema.validate(Schema.java:34)
        at com.sony.antenne.InboundMessage.validate(InboundMessage.java:43)
        at com.sony.antenne.InboundMessage.process(InboundMessage.java:31)



*************************************************************************
The information contained in this message or any of its
attachments may be privileged and confidential and intended 
for the exclusive use of the addressee. If you are not the
addressee any disclosure, reproduction, distribution or other
dissemination or use of this communication is strictly prohibited
*************************************************************************

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


RE: writing a good error handler

Posted by Mark Lines-Davies <ml...@spd.sonybpe.com>.
Hi John K, S

I tried something similar, but the line and column numbers are always -1.

Do I need to do something extra to make this work? I'm using xerces 2.

regards

Mark Lines-Davies

-----Original Message-----
From: John Keyes [mailto:johnkeyes@yahoo.com]
Sent: 13 January 2002 14:06
To: xerces-j-user@xml.apache.org
Subject: Re: writing a good error handler


Hi S,

The API for org.xml.sax.SAXParseException is:

[using xerces 1.4.3 jar]

     public int getColumnNumber();
     public int getLineNumber();
     public java.lang.String getPublicId();
     public java.lang.String getSystemId();

So if you could write your error method as:

     StringBuffer message = new StringBuffer();
     ...
     public void error(SAXParseException ex) {
	message.setLength(0);
         message.append("[ERROR]:").append(ex.getMessage());
         message.append(" at line ").append(ex.getLineNumber());
         message.append(" column ").append(ex.getColumnNumber());
         System.out.println(message);
         Parser.docValid = false;
     }

-John K

S wrote:

> Hi
> now that I could validate an xml against an xsd,
> I need a better error handler that can point out
> the line number in the xml where the error is, in addition to the error.
> is this possible? The in-memory representation of an xml doesnt have
lines,
> so this may not be possible. I am looking for error handling better than
>  public void error(SAXParseException ex) {
>        System.out.println("[ERROR  ]: "+ex.getMessage());
>          Parser.docValid = false;
>  }
>
>
>
> thanks, st.
>
> ---------------------------------------------------------------------
> 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




*************************************************************************
The information contained in this message or any of its
attachments may be privileged and confidential and intended 
for the exclusive use of the addressee. If you are not the
addressee any disclosure, reproduction, distribution or other
dissemination or use of this communication is strictly prohibited
*************************************************************************

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


Re: writing a good error handler

Posted by John Keyes <jo...@yahoo.com>.
Hi S,

The API for org.xml.sax.SAXParseException is:

[using xerces 1.4.3 jar]

     public int getColumnNumber();
     public int getLineNumber();
     public java.lang.String getPublicId();
     public java.lang.String getSystemId();

So if you could write your error method as:

     StringBuffer message = new StringBuffer();
     ...
     public void error(SAXParseException ex) {
	message.setLength(0);
         message.append("[ERROR]:").append(ex.getMessage());
         message.append(" at line ").append(ex.getLineNumber());
         message.append(" column ").append(ex.getColumnNumber());
         System.out.println(message);
         Parser.docValid = false;
     }

-John K

S wrote:

> Hi
> now that I could validate an xml against an xsd,
> I need a better error handler that can point out
> the line number in the xml where the error is, in addition to the error.
> is this possible? The in-memory representation of an xml doesnt have lines,
> so this may not be possible. I am looking for error handling better than
>  public void error(SAXParseException ex) {
>        System.out.println("[ERROR  ]: "+ex.getMessage());
>          Parser.docValid = false;
>  }   
> 
> 
> 
> thanks, st.
> 
> ---------------------------------------------------------------------
> 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