简体   繁体   中英

Parse SAP idoc into Java object

I am trying to parse an SAP idoc XML string into a Java object. I tried using the com.sap.conn.idoc.sapidoc3 artifact into my maven project. This does have all the right tools to parse a XML file I believe, but this also wants me to add a repository/destination to my code. Also I need to add stuff to my classpath which I would like to avoid. The idocs will be sent to me without using any SAP connections, so I actually only need the IDocXMLParser.

Just creating a IDocXMLParser implementation will not work because there are checks on the repository not being null and every constructor is protected.

Is there a way to just parse/unmarshal the received XML string without having to write all the logic myself?

Would you please have a look at my answer here:
Parsing an IDoc in XML format using SAP Java IDoc Class Library ?

I think this should answer your question here, too. If you do not have any RFC connection to an SAP application server with your software, I can only discourage you to use the SAP JCo and the Java IDoc Class Library add-on. They don't provide any benefit in this case.

IDoc-XML parsing for the parsing's sake doesn't make sense, so it depends on which goal you have with this parsing. If you only want to make sure, that the XML is valid and well-formed, you can use any standard XML parser for this. Any other XML parser would also create some Java objects - at least java.lang.String objects. But if you would like to get Java objects of type com.sap.conn.idoc.IDocDocument because you intend to make use of its offered handy navigation, accessor or modifier methods afterwards, then an IDoc-XML parser needs to have access to additional IDoc meta data (which the IDoc-XML itself doesn't provide) for creating these type of objects.

If your intention is to check the IDoc-XML not only for XML validity and well-formedness, but also if it additionally complies to SAP's IDoc-XML specification, I am afraid that the SAP Java IDoc Class Library's IDocXMLProcessor and IDocXMLParser cannot be used for such a separated task, and you really have to write your own parser then in this case.

By the way, you may also have a look at the SAP Business Connector which offers appropriate APIs for dealing with IDocs and IDoc-XML. Of course, this is an integration platform for exchanging business data between various systems, and no development library for being included in own Java application projects. But one can easily develop workflows there, which would cover the desired functionality from your question, I think. I don't know if it would fit to your general project requirements, so this is just another idea with following a different path.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM