on 04-19-2006 5:29 PM
I used the excellent Michal Krawczyk article entitled "Mapping Lookups - RFC API" to get an RFC call to an abap table working. I am now stuck at where to start handling the parsing of the xml response that is returned. Will I be able to put parsing logic in the same java User Defined Function that does the call?
Thanks in advance!
hi Keith,
You will have to use the same UDF to do the paarsing also.
Reason : When the look up is done by the RFC, the response will also be in an XMl format and so, you wil have to parse the XML payload response and reach to that node / element which will contain the corresponding result of the look up. So, do the parsing, get the result of the look up out of the parsing and then finally, return the result out of the UDF.
Ofcourse, another way out would be to have a separate UDF to do the parsing and pass the Payload result of the first UDF as the input to the parsing UDF. But, it is going to contain the same parsing logic right.
Regards,
bhavesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Keith,
First I would suggest you use a DOM parser. Normally , DOm parsers are to be avoided in XI as DOM parser will load the whole XML into the main memory. But , in our case , as we are to be parsing a small XML response , DOM would not cause performance and memory issues and would be easier.
For info on the methods of DOM, just refer to this link,
http://java.sun.com/j2se/1.4.2/docs/api/org/w3c/dom/package-frame.html
http://help.sap.com/saphelp_nw04/helpdata/en/e2/e13fcd80fe47768df001a558ed10b6/content.htm
Also, this blog deals with SAX parser and how to use the same,
/people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-ii
Regards,
Bhavesh
Forgive my ignorance, for I am new to xml parsing with java.
I added the following code to my java udf (where xmlcontent is the rfc-api response). I also added the imports that I believe are required.
DOMParser parser = new DOMParser();
parser.parse(xmlcontent);
Document doc = parser.getDocument();
Nodelist ids = doc.getElementsBYTagName("ZIDNUMBER");
Node id = ids.item(0);
content = (String)id.getFirstChild();
//return to mapping...this existed before my dom additions
return content;
I am getting these errors when running a test. They make it sound like I am not importing something??? Also wonder if the above dom code looks right.
13:14:41 Start of test
Source code has syntax error: /usr/sap/XD0/DVEBMGS02/j2ee/cluster/server0/./temp/classpath_resolver/Map60f706c0cfd011dac06e000d600b4515/source/com/sap/xi/tf/_pan_hotkey_request_RFCinChannel_MM_.java:153: cannot resolve symbol symbol : class Nodelist location: class com.sap.xi.tf._pan_hotkey_request_RFCinChannel_MM_ Nodelist ids = doc.getElementsBYTagName("ZIDNUMBER"); ^ /usr/sap/XD0/DVEBMGS02/j2ee/cluster/server0/./temp/classpath_resolver/Map60f706c0cfd011dac06e000d600b4515/source/com/sap/xi/tf/_pan_hotkey_request_RFCinChannel_MM_.java:153: cannot resolve symbol symbol : method getElementsBYTagName (java.lang.String) location: interface org.w3c.dom.Document Nodelist ids = doc.getElementsBYTagName("ZIDNUMBER"); ^ /usr/sap/XD0/DVEBMGS02/j2ee/cluster/server0/./temp/classpath_resolver/Map60f706c0cfd011dac06e000d600b4515/source/com/sap/xi/tf/_pan_hotkey_request_RFCinChannel_MM_.java:155: inconvertible types found : org.w3c.dom.Node required: java.lang.String content = (String)id.getFirstChild(); ^ 3 errors Source code has syntax error: /usr/sap/XD0/DVEBMGS02/j2ee/cluster/server0/./temp/classpath_resolver/Map60f706c0cfd011dac06e000d600b4515/source/com/sap/xi/tf/_pan_hotkey_request_RFCinChannel_MM_.java:153: cannot resolve symbol symbol : class Nodelist location: class com.sap.xi.tf._pan_hotkey_request_RFCinChannel_MM_ Nodelist ids = doc.getElementsBYTagName("ZIDNUMBER"); ^ /usr/sap/XD0/DVEBMGS02/j2ee/cluster/server0/./temp/classpath_resolver/Map60f706c0cfd011dac06e000d600b4515/source/com/sap/xi/tf/_pan_hotkey_request_RFCinChannel_MM_.java:153: cannot resolve symbol symbol : method getElementsBYTagName (java.lang.String) location: interface org.w3c.dom.Document Nodelist ids = doc.getElementsBYTagName("ZIDNUMBER"); ^ /usr/sap/XD0/DVEBMGS02/j2ee/cluster/server0/./temp/classpath_resolver/Map60f706c0cfd011dac06e000d600b4515/source/com/sap/xi/tf/_pan_hotkey_request_RFCinChannel_MM_.java:155: inconvertible types found : org.w3c.dom.Node required: java.lang.String content = (String)id.getFirstChild(); ^ 3 errors
hi Keith,
try this code,
<b>DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();</b>
// create DOM structure from input XML
<b>DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.parse(inputstream);</b>//inputystream will be the RFC response in your case converted from payload in a Stream
// look for the tag 'ZIDNUMBER'
<b>NodeList list = document.getElementsByTagName("ZIDNUMBER");
Node node = list.item(0);
if (node != null) {</b>
// if found, look for the value of ZIDNUMBER
<b>node = node.getFirstChild();</b><b>if (node != null) {
String zidnumber = node.getNodeValue();
}
}
return zidnumber;</b>
Regards,
Bhavesh
(1) I am getting this warning when testing. Not sure what it refers to. May have something to do with my Document doc statement not being correct.
/usr/sap/XD0/DVEBMGS02/j2ee/cluster/server0/< (A file or directory in the path name does not exist.
(2) The compilation is successful, but I am not getting my return value. The map destination field is just blank. After putting in some debugging statements, it seems like the value I am passing into Document is not of proper format. Any suggestions?
// parse the result (xmlcontent) using DOM
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance( );
DocumentBuilder builder = factory.newDocumentBuilder( );
Document doc = builder.parse(in);
NodeList ids = doc.getElementsByTagName("ZIDNUMBER");
Node id = ids.item(0);
if (id != null) {
id = id.getFirstChild();
content = id.getNodeValue();
}
} catch (SAXException e) {
importanttrace.addWarning(e.getMessage() );
} catch (ParserConfigurationException e) {
importanttrace.addWarning(e.getMessage() );
} catch (IOException e) {
importanttrace.addWarning(e.getMessage() );
}
// return single id value to message mapping
return content;
Message was edited by: Keith Wendel
I just found something about DocumentBuilderFactory. Guess I should be using this instead...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
80 | |
9 | |
9 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.