cancel
Showing results for 
Search instead for 
Did you mean: 

IDOC XML Parsing

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

former_member205363
Contributor
0 Kudos

Hi Martin,

For the XML file processing we have to use XML Parsers, these are bit difficult.

We got the same issue in our project, we written normal java code to parse the xml file.

Do one thing, if the xml file is not big one then take the xml data into a string. parse the string based on characters < and >.

Suppose we have xml data as below

String str = "<emp>employee1</emp>"

You have to get the string between >,<.

Regards,

Lakshmi Prasad.

Answers (1)

Answers (1)

Former Member
0 Kudos

hi,

i have the same problem.

Did you resolve the problem?

thanks.

Emanuel Cordeiro

Former Member
0 Kudos

have the same problem.

Did you resolve the problem?

thanks.

Pasquale