on 08-11-2008 1:32 PM
hello
I have a sync scenario RFC2WS. the answer of the WS is XML that I recieve in a string. I see it like this in the SXMB_MONI
<ns0:setDocumentReturn xmlns:ns0="http://shlomi-dev:81/WS_ImageGeneric.jws"><![CDATA[<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'xmlns:xsd='
http://www.w3.org/2001/XMLSchema'xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><SOAP-ENV:Header></
SOAP-ENV:Header><SOAP-ENV:Body><status><retCode>-15</retCode><retCodeDesc>Doc total pages is: 0 - d:
WS_ATTACH
ATTACH_SOA_0_01_012345678_115_5544_142720587_0.pdf</retCodeDesc></status></
SOAP-ENV:Body></SOAP-ENV:Envelope>]]></ns0:setDocumentReturn>
I would like to know how can I recieve a specific parameters to the RFC?
I wrote this code, but it doesnt map correctly so I believe that I miss something, or didnt wrote the code correctly.
the java code is:
String value="";
try{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// create DOM structure from input XML
DocumentBuilder builder = factory.newDocumentBuilder();
ByteArrayInputStream bais=new ByteArrayInputStream(a.getBytes());
Document document = builder.parse(bais);
NodeList list = document.getElementsByTagName("retCode");
Node node = list.item(0);
if (node != null) {
node = node.getFirstChild();
}
if (node != null) {
value = node.getNodeValue();
}
}
catch(Exception e){
}
return value;
what am I doing wrong in order to get to the RFC on the retCode element value?
Thanks
Kfir
Hello Kfir,
Try putting these statements in your IMPORT parameters:
javax.xml.transform.stream.StreamResult;com.sap.aii.mapping.lookup.*;
javax.xml.transform.dom.DOMSource;javax.xml.parsers.*;
javax.xml.transform.*;
org.w3c.dom.*;
org.xml.sax.*;
Then write this in the code section:
String value="";
try{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// create DOM structure from input XML
DocumentBuilder builder = factory.newDocumentBuilder();
ByteArrayInputStream bais=new ByteArrayInputStream(a.getBytes());
Document document = builder.parse(bais);
// look for the tag 'retCode'
NodeList list = document.getElementsByTagName("retCode");
Node node = list.item(0);
if (node != null) {
// if found, look for the value of 'retCode'
node = node.getFirstChild();
}
if (node != null) {
value = node.getNodeValue();
}
}
catch(Exception e){
}
return value;
Hope that helps!
Glenn
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
You are trying to parse the entire xml and find out the value of retCode, but this field is a child of CDATA element, thus when you parse the XML CDATA elelments are not parsed thus you will never retrive the value of retCode.
Try the below code:
First of all code clears of the name spaces for CDATA element (they are coming with inocrrcet character in name space) then the string a is parsed twice.
String constant1 = "xmlns:xsd='http://www.w3.org/2001/XMLSchema'";
String constant2 = "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'";
String constant3 = "xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'";
String constant4 = "SOAP-ENV:";
a = a.replaceAll(constant1, "");
a = a.replaceAll(constant2, "");
a = a.replaceAll(constant3, "");
a = a.replaceAll(constant4, "");
String value = "";
try {
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
ByteArrayInputStream bais = new ByteArrayInputStream(a.getBytes());
Document document = builder.parse(bais);
NodeList list =
document.getElementsByTagName("ns0:setDocumentReturn");
Node node = list.item(0);
if (node != null)
node = node.getFirstChild();
if (node != null)
value = node.getNodeValue();
bais = new ByteArrayInputStream(value.getBytes());
document = builder.parse(bais);
list = document.getElementsByTagName("retCode");
node = list.item(0);
if (node != null)
node = node.getFirstChild();
if (node != null)
value = node.getNodeValue();
} catch (Exception e) {
}
return value;
Regards,
KNS Kumar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
HI Kfir.
If I understand you correctly you expect the value of -15 to be mapped?
In that case your code is correct. What is the result you are getting at the moment?
Rod
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.