Eviware Forum

soapUI => soapUI => Topic started by: PeterT on March 19, 2008, 12:39:26 am



Title: How to call 'Format XML' programmatically
Post by: PeterT on March 19, 2008, 12:39:26 am
Hi again

Does anyone know how to call 'Format XML' (as in the function available from the right-click menu when in a Request) programmatically?

I had to populate some elements in a request using the XMLParser method defined in the user docs.  Usually I would use the much simpler methods on the XmlHolder class e.g.holder["//path"] = value but because I have a complex type that has 2 same named elements in them I couldn't get work out how to write to the second element.

e.g.<Accounts>
         <Account>
           <Value></Value>
        </Account>
        <Account>
           <Value></Value>
       </Account>
      </Accounts>

Anyway, I successfully managed to update the values but the new XML generated puts each tag or end tag on a new line and appears to add whitespace to some of the existing values.  When I 'Format XML' this is remedied but I need to be able to call 'Format XML' from within my script.

If anyone can let me in on how to do this that'd be great.

Cheers

Peter


Title: Re: How to call 'Format XML' programmatically
Post by: omatzura on March 19, 2008, 12:45:58 am
Hi Peter,


try

def xml = .. create XML string..
xml = com.eviware.soapui.support.xml.XmlUtils.prettyPrintXml( xml )

Hope this helps!

regards,

/Ole
eviware.com


Title: Re: How to call 'Format XML' programmatically
Post by: PeterT on March 19, 2008, 01:21:29 am
Awesome, it worked! Thanks for your help again Ole  :)