[QVTO] Black-box problem with XML [message #690854] |
Thu, 30 June 2011 06:28 |
Eclipse User |
|
|
|
Hi there,
I try to make a ecore M2M-Transformation with qvto.
To make the transformation I need a specific value from an xml-File.
Therefor I use XPath in Java.
Via Blackbox in qvto I try to use the function in Java and return the value as a String.
The call of the java function from qvto works and its also possible to return a string.
The java function to read from the xml file also works in java and returns the specific value.
Only if I call the function from qvto and want to return the specific value it doesn't work.
I focused the problem to the last line.
public static String getInstallPart(String os, String db, String shortname, int installPart) {
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
domFactory.setNamespaceAware(true);
DocumentBuilder builder = null;
Document doc = null;
XPath xpath = null;
XPathExpression expr = null;
Object result = null;
try {
builder = domFactory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
doc = builder.parse(xmlPath);
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
xpath = XPathFactory.newInstance().newXPath();
try {
expr = xpath.compile("//OS[@name='"+ os +"']/DB[@name='"+ db +"']/SAP[@name='"+ shortname +"']/InstallPart["+ installPart +"]/@name");
} catch (XPathExpressionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
result = expr.evaluate(doc, XPathConstants.STRING);
} catch (XPathExpressionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result.toString() + "test";
}
If I call this function from a java main method with the same parameter then from qvto it works fine and the result is the resultString + "test".
But if I call this function from qvto it returns nothing. Not even the "test"-String.
If I change the last line to:
it returns the String to qvto.
So it has to be a problem with the conversion of the variable result from an Object to a String.
But I don't have an idea what to change to make it work.
Can anyone help me?
Thanks a lot!
|
|
|
Powered by
FUDForum. Page generated in 0.07512 seconds