cancel
Showing results for 
Search instead for 
Did you mean: 

Problem using SAP XML Toolkit

Former Member
0 Kudos

While using the SAP XML Tookit for a java mapping in the XI (actual we use SAP XI 3.0 SP13), we get an error when we try to use the XPath functions of the Toolkit. The class XPathNSResolverImpl causes the main problem. The class do not analyse the given node correctly which is used to resolve the namespaces. This results in later Problems while using the method evaluate from the class XPathEvaluatorImpl, because XML documents with namespaces could not be searched correctly via XPath.

The following example program ends with a NullPointerException when calling the method lookupNamespaceURI from the class XPathNSResolver.

package de.ottawa.test;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import com.sap.engine.lib.xml.dom.xpath.XPathEvaluatorImpl;
import com.sap.engine.lib.xml.dom.xpath.XPathNSResolverImpl;
public class TestXPathNSResolverImpl {
 TestXPathNSResolverImpl() {
 }
 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  TestXPathNSResolverImpl impl = new TestXPathNSResolverImpl();
  impl.testResolver();
 }
 private void testResolver() {
  try {
   DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
   factory.setNamespaceAware(true);
   System.out.println("FactoryClass: " + factory.getClass().getName());
   DocumentBuilder builder = factory.newDocumentBuilder();
   System.out.println("DOMBuilder Class : " + builder.getClass().getName());
   Document doc = builder.parse(this.getClass().getResourceAsStream(
     "XPathConfig.xml"));
   ;
   System.out.println("Document Class: " + doc.getClass().getName());
   XPathEvaluatorImpl xPathEval = new XPathEvaluatorImpl();
   XPathNSResolverImpl nsResolver = xPathEval.createNSResolver(doc);
   System.out.println("XPathNSResolver Class: " + nsResolver.getClass().getName());

    System.out.println("Namespace URI: " + nsResolver.lookupNamespaceURI("p2"));

  } catch (Exception ex) {
   System.out.println(ex.toString());
  }
 }
}

The classpath is defined as follows: J2SE and SAP XML Toolkit.

The file "XPathConfig.xml", which is included in the package, has the following content:

<?xml version="1.0" encoding="UTF-8"?>
<p2:One path="//p2:Message1/p3:MT_ServiceObject/Control" xmlns:p2="http://sap.com/xi/XI/SplitAndMerge" xmlns:p3="http://abc.de/xi/kuba/ESVehicleSales"/>

The output of the method main looks like:

FactoryClass: com.sap.engine.lib.jaxp.DocumentBuilderFactoryImpl
DOMBuilder Class : com.sap.engine.lib.jaxp.DocumentBuilderImpl
Document Class: com.sap.engine.lib.xml.dom.DocumentImpl
XPathNSResolver Class: com.sap.engine.lib.xml.dom.xpath.XPathNSResolverImpl
java.lang.NullPointerException

Alternatively when using the Xerces and Xalan framework from the Apache Foundation and adjusting the class creation in line 47 (XPathNSResolver nsResolver = xPathEval.createNSResolver(doc);) the following output appears:

FactoryClass: org.apache.xerces.jaxp.DocumentBuilderFactoryImpl
DOMBuilder Class : org.apache.xerces.jaxp.DocumentBuilderImpl
Document Class: org.apache.xerces.dom.DeferredDocumentImpl
XPathNSResolver Class: org.apache.xpath.domapi.XPathNSResolverImpl
Namespace URI: http://sap.com/xi/XI/SplitAndMerge

Can someone tell me, why the class won't work? Is this a bug in the XML Toolkit?

Accepted Solutions (1)

Accepted Solutions (1)

MichalKrawczyk
Active Contributor
0 Kudos

hi,

you might want to have a look at an alternative:

/people/amjad-ali.khoja/blog/2006/02/07/using-dom4j-in-xi--a-more-sophisticated-option-for-xml-processing-than-sap-xml-toolkit

Regards,

michal

-


<a href="/people/michal.krawczyk2/blog/2005/06/28/xipi-faq-frequently-asked-questions">XI FAQ - Frequently Asked Questions</a>

Former Member
0 Kudos

Hi Michal,

thanks for that hint. I know that weblog. Because of this one I have had the idea to use Xerces and Xalan.

But I hoped, that someone could tell me a workaround with the SAP Standard Toolkit, because we have the demand to use Standard Techniques when programming Java Mappings.

Best Regards,

Lars

Answers (1)

Answers (1)

bhavesh_kantilal
Active Contributor
0 Kudos

Hi Lars,

While doing Java Mapping for XI, XI will call the EXECUTE method from your class internally and process the steps in the exceute method.

From your code, there is no execute method and that is why, I think the null pointer exception might have occured.

Also, your class should implement the StreamTransformation interface that contains the 2 methods ,

Execute and setParameter

Just check this link for the 2 mandatory methods that have to be implemented,

http://help.sap.com/saphelp_nw04/helpdata/en/e2/e13fcd80fe47768df001a558ed10b6/content.htm

Regards,

Bhavesh

Former Member
0 Kudos

Hi Bhavesh,

the program I mentioned in my thread is a proof of concept. I know that we have to implements the StreamTransformation interface in Java Mappings.

The problem is that the class XPathNSResolver seems to have a bug. The example program should show the resulting error only. It is not the Java Mapping itself.

It seems to be the same error which is mentioned in the Xalan bugzilla database:

<a href="http://marc2.theaimsgroup.com/?l=xalan-dev&m=106977993631579&w=3">http://marc2.theaimsgroup.com/?l=xalan-dev&m=106977993631579&w=3</a>

But nevertheless, thanks for your answer.

Best Regards,

Lars