Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.
Can Method Tool return custom XML structure
LegacyForum
Posts: 1,664 ✭✭
Normally, when I want to return an XML structure in a Method tool to be chained with a Data Bank I use the command:
return SOAPUtil.getXMLFromString(["myStringList"]
The format is always a simple list:
<root>
<z0>myString1</z0>
<z1>myString2</z1>
...
</root>
Is there a way (either in Java or Jython) that I can create my own XML structure, like say:
<myTop>
<name>column1</name>
<value>Under Name1</value>
<name>column2</name>
<value>Under Name2</value>
...
</myTop>
It is unclear in the Online help what object I need to return in the Method Tool. All I know is the SOAPUtil.getXMLFromString() returns a java.lang.Object
Thanks.
return SOAPUtil.getXMLFromString(["myStringList"]
The format is always a simple list:
<root>
<z0>myString1</z0>
<z1>myString2</z1>
...
</root>
Is there a way (either in Java or Jython) that I can create my own XML structure, like say:
<myTop>
<name>column1</name>
<value>Under Name1</value>
<name>column2</name>
<value>Under Name2</value>
...
</myTop>
It is unclear in the Online help what object I need to return in the Method Tool. All I know is the SOAPUtil.getXMLFromString() returns a java.lang.Object
Thanks.
0
Comments
-
Hi Kevin,
The XML Data Bank expects an object called Text. This class has a MIME Type, and the XML Data Bank expects this to be text/xml. So there are two ways of accomplishing what you want, and both require that you build the XML yourself into a String:
1) Create and return a new Text with your XML String, and set its MIME Type to text/xml:CODEfrom com.parasoft.api import *
def option1(input, context):
myXML = "<myTop> <name>column1</name> <value>Under Name1</value> <name>column2</name> <value>Under Name2</value></myTop>"
return Text(myXML, "text/xml")
2) Use the SOAPUtil.getXMLFromString(String[], boolean) method. This alternative form of getXMLFromString() takes a boolean, which indicates whether the String[] argument is already an XML document. If it is, then the proper Text object is automatically built and returned.
CODEfrom com.parasoft.api import *
from soaptest.api import *
def option2(input, context):
myXML = "<myTop> <name>column1</name> <value>Under Name1</value> <name>column2</name> <value>Under Name2</value></myTop>"
return SOAPUtil.getXMLFromString([myXML], 1)0