Let me elaborate.
The following is an example taken from
http://www.ibm.com/developerworks/xml/library/x-tipstx4/
Which has been modified to show my point. It uses stax, and when an
error is thrown
while writing to the stream, I can recover gracefully and send back well
formed xml with
an error element.
public class WriterExample
{
// Namespaces
private static final String GARDENING = "http://com.bdaum.gardening";
private static final String XHTML = "http://www.w3.org/1999/xhtml";
public static void main(String[] args) throws XMLStreamException {
XMLOutputFactory xmlof = XMLOutputFactory.newInstance();
XMLStreamWriter xmlw =
xmlof.createXMLStreamWriter(System.out);
try
{
// Write XML prologue
xmlw.writeStartDocument();
// Write a processing instruction
xmlw.writeProcessingInstruction(
"xml-stylesheet href='catalog.xsl' type='text/xsl'");
// Now start with root element
xmlw.writeStartElement("product");
// Set the namespace definitions to the root element
// Declare the default namespace in the root element
xmlw.writeDefaultNamespace(GARDENING);
// Writing a few attributes
xmlw.writeAttribute("productNumber","3923-1");
xmlw.writeAttribute("name","Nightshadow");
// Different namespace for description element
xmlw.writeStartElement(XHTML,"description");
if(true)
throw new Exception();
xmlw.writeCharacters(
"A tulip of almost black color. \nBlossoms in April & May");
xmlw.writeEndElement();
// Shorthand for empty elements
xmlw.writeEmptyElement("supplier");
xmlw.writeAttribute("name","Floral22");
}
catch(Exception e)
{
xmlw.writeEndElement();
xmlw.writeStartElement(XHTML,"error");
xmlw.writeCharacters("A System Error Occured");
xmlw.writeEndElement();
}
finally
{
xmlw.writeEndDocument();
xmlw.close();
}
}
}
Notice I am throwing an Exception. This would be similar to a
JibxException being thrown during marshalling.
However, I catch this exception, add an error element as the end
element, then call writeEndDocument which
closes all open structures. Can something similar be done with jibx?
instead of sending back xml that is
not well formed?
Peter
--------------------------------------------------------
NOTICE: If received in error, please destroy and notify sender. Sender does not
intend to waive confidentiality or privilege. Use of this email is prohibited
when received in error.
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users