Skip to Content
author's profile photo Former Member
Former Member

IDOC XML Parsing

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

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Best Answer
    Posted on Feb 25, 2009 at 05:54 AM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 12, 2011 at 02:29 PM

    hi,

    i have the same problem.

    Did you resolve the problem?

    thanks.

    Emanuel Cordeiro

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.