on 08-21-2006 3:44 PM
Hi
I got the following XML stream
"
<?xml version="1.0" encoding="UTF-8"?><rfc:ZFI_CHECK_RATE.Response xmlns:rfc="urn:sap-com:document:sap:rfc:functions"><C_UKURS>4.20000</C_UKURS></rfc:ZFI_CHECK_RATE.Response>"
I want to write user defined function which will return me only the value of the C_UKURS node (4.20000)
any ideas?
thx,Shai
Hi,
do the search in the string for C_UKURS
and take the value from > to <
if it occurs only once
Regards,
michal
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I wrote the following function
DOMParser parser = new DOMParser();
InputSource input = new InputSource(a);
parser.parse(input);
Document MyDoc = parser.getDocument();
String value = MyDoc.getDocumentElement().getFirstChild().getNodeValue();
return value;
and I get the following error
/usr/sap/XID/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapc468dbd0312c11dbbb63001125a56002/source/com/sap/xi/tf/_FI_CURR_MM_.java:258: unreported exception org.xml.sax.SAXException; must be caught or declared to be thrown parser.parse(input); ^ 1 error
any Ideas?
Shai,
put the code in a try catch block,
try{
DOMParser parser = new DOMParser();
InputSource input = new InputSource(a);
parser.parse(input);
Document MyDoc = parser.getDocument();
String value = MyDoc.getDocumentElement().getFirstChild().getNodeValue();
}
catch(Exception e){
}
return value;
Regards,
Bhavesh
Message was edited by: Bhavesh Kantilal
thx Bhavesh for the answer
now IM getting the following error
usr/sap/XID/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mape0e7c070312f11db91e7001125a56002/source/com/sap/xi/tf/_FI_CURR_MM_.java:265: cannot resolve symbol symbol : variable value location: class com.sap.xi.tf._FI_CURR_MM_ return value;
Okie.. got it, This will solve the issue.
<i>String value;</i>
try{
DOMParser parser = new DOMParser();
InputSource input = new InputSource(a);
parser.parse(input);
Document MyDoc = parser.getDocument();
value = MyDoc.getDocumentElement().getFirstChild().getNodeValue();
}
catch(Exception e){
}
return value;
Regards,
Bhavesh
Shai,
Try this code,
String value;
try{
DOMParser parser = new DOMParser();
InputSource input = new InputSource(a);
parser.parse(input);
Document MyDoc = parser.getDocument();
// look for the tag 'C_UKURS'
<i>NodeList list = document.getElementsByTagName("C_UKURS");
Node node = list.item(0);
if (node != null) {
// if found, look for the value of 'C_UKURS'
node = node.getFirstChild();
if (node != null) {
value = node.getNodeValue();</i>
}catch(Exception e){
}
return value;
Regards,
Bhavesh
u have it int he begging of the forum
btw I changed your code a bit to fix the errors
//write your code here
String value = "";
try{
DOMParser parser = new DOMParser();
InputSource input = new InputSource(a);
parser.parse(input);
Document MyDoc = parser.getDocument();
// look for the tag 'C_UKURS'
NodeList list = MyDoc.getElementsByTagName("C_UKURS");
Node node = list.item(0);
if (node != null) {
// if found, look for the value of 'C_UKURS'
node = node.getFirstChild();
}
if (node != null) {
value = node.getNodeValue();
}
}catch(Exception e){
}
return value;
Shai,
Try this code,
String value="";
try{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// create DOM structure from input XML
DocumentBuilder builder = factory.newDocumentBuilder();
ByteArrayInputStream bais=new ByteArrayInputStream(<b>a.getBytes()</b>);
Document document = builder.parse(bais);
// look for the tag 'C_UKURS'
NodeList list = document.getElementsByTagName("C_UKURS");
Node node = list.item(0);
if (node != null) {
// if found, look for the value of 'C_UKURS'
node = node.getFirstChild();
}
if (node != null) {
value = node.getNodeValue();
}
}
catch(Exception e){
}
return value;
In the above code, I have assumed that "a" is the input to the User Defined Function and is a String containing the XML.
Regards,
Bhavesh
User | Count |
---|---|
81 | |
10 | |
10 | |
9 | |
7 | |
6 | |
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.