Hi Everyone.
I've got some lovely XML IDocs. I'd like to read them into the IDOC Class Library and send them to SAP with JCo..........
But I can't get some simple code to parse the XML. I've been sending XMLs to SAP for a long time and they were always valid in SAP. They are also valid XML.
I also borrowed the code directly out of the JCo documentation, so you'd think it would work.
I'm using Java 6, IDoc Class lib 3.01. I've also tried Java 5. If I could parse the XML I would be using SAP 4.7 and JCo 3.01....
I've used JDOM for creating my XML. I've tried UTF-8 and ISO-8859-1 encoding. The error doesn't change
The error message i get is IDOC_ERROR_PARSE_FAILURE: Invalid charachter encountered in XML input data sourcee: state=EXPECTING_IMMEDIATE_TAG_END, charPosition=48, lineNumber=1, columnNumber=49, invalidChar=U+0053, sourceSnippet=...<?xml version "1.0" encoding="UTF-8"?>....
Heres my function I'm using.
(getRfcConnection is my own helper function to create a RFC Destination)
The rest of it is really just copied + pasted from the documentation.
public static void submitXml(Sap_Pruefziffer sap_pruefziffer, String language,String iDocXML)
throws JCoException, CS_Rfc_Exception, AbapException, IDocParseException
{
JCoDestination destination = getRfcConnection(sap_pruefziffer,language);
IDocRepository iDocRepository = JCoIDoc.getIDocRepository(destination);
String tid = destination.createTID();
IDocFactory iDocFactory = JCoIDoc.getIDocFactory();
//this would be great for re-implementing the OrderDataFactory
//although that works just fine
// a) create new idoc
/*IDocDocument doc = iDocFactory.createIDocDocument(iDocRepository,"MATMAS02");
IDocSegment segment = doc.getRootSegment();
segment = segment.addChild("E1MARAM");
// and so on. See IDoc Specification .....
JCoIDoc.send(doc, IDocFactory.IDOC_VERSION_DEFAULT, destination, tid);*/
// b) use existent xml file
//get IDOC XML/IDOC Parser
IDocXMLProcessor processor=iDocFactory.getIDocXMLProcessor();
//parse the XML/IDOC
IDocDocumentList iDocList=processor.parse(iDocRepository, iDocXML);//, IDocXMLFormat.SAP_RELEASE_610, IDocXMLProcessor.PARSE_WITH_FIELD_VALUE_CHECKING
//send the XML/IDOC per RFC (our destination)
JCoIDoc.send(iDocList, IDocFactory.IDOC_VERSION_DEFAULT, destination, tid);
//not really sure what this does
destination.confirmTID(tid);
}
Thanks for your help in advance
Martin