Forum Discussion

PeterT's avatar
PeterT
Occasional Contributor
17 years ago

How to call 'Format XML' programmatically

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.
       
         
       

       
         
     

     


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

2 Replies

  • omatzura's avatar
    omatzura
    Super Contributor
    Hi Peter,


    try

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

    Hope this helps!

    regards,

    /Ole
    eviware.com
  • PeterT's avatar
    PeterT
    Occasional Contributor
    Awesome, it worked! Thanks for your help again Ole