Hi Andy,

You catched exactly what I need. I've already implemented your solution and it works great! In combination with a file like the XMLSchemaMessages.properties I think I can return my own error messages using my own format.

BTW, congratulations to who designed all this registered-components stuff.

Thanks
Jorge



Andy Clark wrote:

Jorge Ortiz Claver wrote:

Problem appears when my client, instead of error messages like

"The value 'AAA' of attribute 'code' on element 'comm-response' is not valid with respect to its type, 'integer'.]"

(SAXException message) would like to receive error information codified. Client only wants to receive a code for the tag that produced the error (in this case, we will send a code assigned to tag 'AAA') and line/column information wouldn't be enough for him.


Let me see if I understand your request. You would rather have
the pieces of information for the error than a localized message
containing those values. Correct?

For example, you would rather have the following information (for
the error shown above):

  errorcode: elem.attr.value.invalid.to.type
  element:   comm-response
  attribute: code
  type:      integer
  value:     "AAA"

If this is the case, then there might be something you can do.

By default, the Xerces components report errors by passing the
following information to an error reporter: error level, domain,
key, and an array of values related to the error domain/key. For
the above error, for example, something like the following is
reported:

  level:  ERROR
  domain: "http://www.w3.org/XMLSchema/blah/blah/blah";
  key:    "elem.attr.value.invalid.to.type"
  array:  [ "comm-response", "code", "integer", "AAA" ]

The Xerces error reporter then looks up a the message formatter
responsible for the specified domain, localizes the message
with the given key and array of values, and that is what is
reported to the SAX ErrorHandler.

Make sense so far?

The Xerces error reporter is a registered component just like
everything else in the parser. This means that you can override
the default error reporter and replace it with your own. And
in *your* error reporter, you don't have to localize the
messages.

In fact, for your purposes, you probably only need to report
the key and array of values. You still have to produce a String
from this information but you can do it any way that you want.
I would recommend tab-separating the values. For example:

  StringBuffer str = new StringBuffer();
  str.append(key);
  for (int i = 0; i < array.length; i++) {
    str.append("\t");
    str.append(array[i]);
  }

Then you just set the appropriate property on the parser and
all of your error messages will be reported in your format!
Your application then would split the error messages at the
tabs, pull out the key and values, and map that information
to any application-specific message or notification that you
want.

I am, of course, leaving out a lot of details but I didn't
want to get too specific until I'm sure that I understand your
request properly. If this is on the right track, though, please
read the "XNI Manual" in the documentation for information
about the XMLErrorReporter component.

Also look at the code for the default error reporter to see
how you can extend it to provide the error reporting that you
want. Then, just call setProperty() with the property id of
the internal error reporter component and your new error
reporter instance.

I hope this helps.




--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to