I am generating a XML file and retrieving all the elements (includin attachment) from the XML. The steps are mentioned below:
1) Generate a XML file based on schema. 2) Attach a file (ex. PDF, doc, image etc) to the XML 3) Sign the generated XML file using XMLDsig 4) Send the file to client 5) Parse the XML file to retrieve all elements includin the attachment file.
I am facing problem in step (5) while parsing the attachment tag. The error is as followings:
org.xml.sax.SAXParseException: The content of elements must consist of well-formed character data or markup. at org.apache.xerces.framework.XMLParser.reportError(XMLParser.java:1213) at org.apache.xerces.framework.XMLDocumentScanner.reportFatalXMLError(XMLDocumentScanner.java:570) at org.apache.xerces.framework.XMLDocumentScanner.abortMarkup(XMLDocumentScanner.java:624) at org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(XMLDocumentScanner.java:1194) at org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.java:381) at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1098) at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:195) at javax.xml.parsers.DocumentBuilder.parse(Unknown Source) at XMLSignGen.main(XMLSignGen.java:70)
The error message explains how to resolve the problem: it says "The content of elements must consist of well-formed character data or markup" so you need to make sure that is the case.
I don't understand step (2) in your algorithm though. Does that mean you just tack the file onto the XML after the closing tag of the root element? Or does it actually go into a text node inside the element? And do you realize that XML is a text format that cannot contain arbitrary binary data such as that found in images and PDF and MS Word documents?
Joined: Feb 28, 2004
Thanks for prompt reply. Actually the steps I have mentioned in my query that is my work requirement. Curently I am trying to run a stand-alone program. So I have created a SOAP message. Then I am attaching a PDF file to the SOAP message. After that while I am trying to parse the message, I am facing the mentioned (in my first query) error.
The attachment is being done in encoding format. So "The content of elements"(only for attachment tag) get changed
Nope. Because I don't understand what it means to "attach" a file to a SOAP message. And I don't understand what that "encoding format" is. However you have done it incorrectly in some way -- and that's all I can really say because I know very little about SOAP. I would look at the "encoding format" and see what it's doing. Or better still I would look at the XML being produced as SOAP message and see what is wrong with it.
Joined: Feb 28, 2004
I have never worked on SOAP. SO I too know less about it.
First I am creating a SOAP message and then attaching a PDF file using the following code: