on 06-28-2007 11:41 PM
Hi everyone!
First, I must say that I don't know anything about java/XML programming(I'm sorry)!
I'm just looking for some guiding lights for the following;
In the Message Mapping (IB), I'm trying to do a RFC Lookup to R/3 using a BAPI call. I followed Michal Krawczyk's "Mapping lookups - RFC API:
"
And now I need to parse the XML response and retrieve a value from it!
I would like to know if the following portion of code is ok and wheere should I put it?
Code:
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// Create DOM structure
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(content);
// Lets find my tag
NodeList list = document.getElementsByTagName("Number");
Node node = list.item(0);
if (node != null) {
node = node.getFirstChild();
}
if (node != null) {
tagValue = node.getNodeValue();
}
Thanks a lot for your help!
Thank you for the links!!!
I've consulted all of them and when I try to run the code, I'm getting the following message:
unreported exception org.xml.sax.SAXException; must be caught or declared to be thrown document = builder.parse(result.getContent());
Could you help me fix that issue?
Here's the code in question
String m = "<?xml version="+"1.0" "encoding=""UTF-8""?>"
"<ns0:BAPI_CUSTOMER_FIND""xmlns:ns0=""urn:sap-com:document:sap:rfc:functions>"+"<RESULT_TAB></RESULT_TAB><SELOPT_TAB><item><COMP_CODE>1000</COMP_CODE><TABNAME>KNA1</TABNAME><FIELDNAME>SORTL</FIELDNAME><FIELDVALUE>004258</FIELDVALUE></item></SELOPT_TAB></ns0:BAPI_CUSTOMER_FIND>";
RfcAccessor accessor = null;
ByteArrayOutputStream out = null;
importanttrace = null;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = null;
factory.setNamespaceAware(false);
factory.setValidating(false);
Document document = null;
try
{
builder = factory.newDocumentBuilder();
} catch (Exception e) {
importanttrace.addWarning("Error creating DocumentBuilder -" + e.getMessage());
return null;
}
try
{
//1. Determine a channel (Business system, Communication channel).
Channel channel = LookupService.getChannel ("BS_FSCM_AR_CLNT100","CC_RFC_TEST");
//2. Get a RFC accessor for a channel.
accessor = LookupService.getRfcAccessor(channel);
//3. Create a xml input stream representing the function module request message.
InputStream inputStream = new ByteArrayInputStream(document.toString().getBytes());
//4. Create xml payload.
XmlPayload payload = LookupService.getXmlPayload(inputStream);
//5. Execute lookup.
Payload result = accessor.call(payload);
document = builder.parse(result.getContent());
//InputStream in = result.getContent();
out = new ByteArrayOutputStream(1024);
byte [] buffer = new byte[1024];
for (int read = inputStream.read(buffer); read > 0; read = inputStream.read(buffer)) {
out.write(buffer, 0, read);
}
content = out.toString();
Thanks for your help!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Tersant,
You can cross check your code as mentioned in this weblog:
/people/bhavesh.kantilal/blog/2006/11/20/webservice-calls-from-a-user-defined-function
Regards,
---Satish
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Tersant,
You can also get the value like mentioned in the weblog:
/people/wojciech.gasiorowski/blog/2006/11/01/the-power-of-regular-expressions-in-graphical-mapping-xi
Check point 5.
Regards,
---Satish
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.