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 Andrew Anand <an...@fedex.com> on 2002/04/30 17:59:25 UTC

xerces parser's exception message turns xml file invalid

In my java-xml application, the request( xmlfile.in) and
response(xmlfile.out) are xml files.

When I send in an invalid xml request, the xerces parser throws the
exception (eg. SAXException) expectedly.
This exception message is included inside <ErrorMsg> element that exists in
my XML response file(xmlfile.out).
But this exception message includes the xml mark up ( special characters)
which is causing the response xml to become invalid and not wellformed.
But I am required to send back the exception message as much as possible,
but still retain the XML response file to be valid and well-formed.

********************  Problem description in detail follows
*************************************************************

-----------------  Example request XML file (xmlfile.in)----------------
1.<?xml version="1.0" encoding="UTF-8"?>
2.	<!DOCTYPE ChapterWordSearchRequest SYSTEM "ChapterWordSearchRequest.dtd">
3.		<ChapterWordSearchRequest>
4.			<GTeHRequest>
7.				<RequestData>
8.					<CommodityKeyword>Wool</CommodityKeywo
9.				</RequestData>
10.			</GTeHRequest>
11.		</ChapterWordSearchRequest>
--------------------------------------------------------------
Note : In the above xmlfile.in, line number 8 contains incomplete closing
tag for <CommodityKeyword> which makes it be not to be a well-formed xml.

---------------- XML response file (xmlfile.out) -----------------
1.<?xml version="1.0" encoding="UTF-8"?>
2.	<!DOCTYPE ChapterWordSearchReply SYSTEM "ChapterWordSearchReply.dtd">
3.		<ChapterWordSearchReply>
4.		     <GTeHReply>
5.	       		<Error>
6.				<ErrorCode>11111</ErrorCode>
7.				<ErrorMsg>
8.					[
9.					INVALID XML REQUEST:
10.		 			SAXException occured while parsing xml request.
11.					 Possible Reasons :INVALID XML REQUEST : NON-RECOVERABLE ERROR :
12.					  Message: The element type "CommodityKeyword" must be terminated by
the matching end-tag "</CommodityKeyword>
13					  </CommodityKeyword>".
14.					  Column: 308
15.					  Line: 1
16.					  Public ID: null
17.					   System ID: null
18.					]
19.				</ErrorMsg>
20.
21.			</Error>
22.		     </GTeHReply>
23.		</ChapterWordSearchReply>
-------------------------------------------------------------
Problem : In the above file(xmlfile.out) lines 12 and 13(containing tag
</CommodityKeyword> ) cause it not to become a well formed xml.

I think the problem is because of the tags(shown below) introduced in the
parser's exception message that appears in xmlfile.out is casuing
it(xmlfile.out) not to be a well-formed and valid xml document .
  Message: The element type "CommodityKeyword" must be terminated by the
matching end-tag "</CommodityKeyword>
</CommodityKeyword>".


Hint:  If I delete  "</CommodityKeyword> </CommodityKeyword>"  portion of
xmlfile.out,  it becomes a well-formed and valid XML

I am using xerces 1.4.

May I know how to be able to send the exception message in </ErrorMsg> tag
and still retain the well-formedness and validity of the xml
response(xmlfile.out).

Thank you,
Andrew
FedEx IT Services