Can Method Tool return custom XML structure

LegacyForumLegacyForum Posts: 1,669 ✭✭
edited December 2016 in SOAtest
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:

Is there a way (either in Java or Jython) that I can create my own XML structure, like say:

<value>Under Name1</value>
<value>Under Name2</value>

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



  • LegacyForumLegacyForum Posts: 1,669 ✭✭
    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:

    from 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)
Sign In or Register to comment.