cancel
Showing results for 
Search instead for 
Did you mean: 

Convert Collection to XML

BrianneGacad
Level 3

Hi All,

Just wondering if anyone has come across a solution of converting a collection to XML.

XML is to be then used by a SOAP API. 

Similarly and not sure if this is even the best way but has anyone encountered a solution where it converts a json directly to an xml file for API consumption?

Looking forward to your inputs!

Thanks!

Brian



------------------------------
Brianne Gacad
Senior IT Domain Specialist
Telstra
Australia/Melbourne
------------------------------
6 REPLIES 6

John__Carter
Staff
Staff
Hi Brianne - if you push the collection into a code stage as an input parameter, you can treat it as a DataTable object, and there will be plenty of conversion examples to borrow from. That said, debugging code in BP can be painful because the code stage is not an IDE, really it's just an execution mechanism. So for anything non-trivial, use a true code editor to get the code right before pasting into BP.

------------------------------
John Carter
Professional Services
Blue Prism
------------------------------

GopalBhaire
Level 10

I posted the same to other question, maybe it'll work for you.

You can loop over the collection and use a multicalc to generate the desired XML.

OR you can use code stage with collInput (collection) as input and xmlResult (text) as output. 

Dim sw as Object
sw = new StringWriter() 
collInput.WriteXml(sw)
xmlResult = sw.ToString()​​


------------------------------
Gopal Bhaire
Analyst
Accenture
------------------------------

Hi Gopal,
Had the same question and tried your solution above but encountered this error:

Page: Action 1
Stage: Code1
Type: Error
Action: Validate
Description: Compiler error at line 2: Type 'StringWriter' is not defined.
Repairable: No

Any idea what the cause and fix is?

thanks

------------------------------
Bwalya Kasase
------------------------------

Hi Bwalya try changing the line to this.

sw = new System.IO.StringWriter

------------------------------
John Carter
Professional Services
Blue Prism
------------------------------

Hi Bwalya,

maybe you have forgotten to import the namespace "System.IO"? Or easier replace "StringWriter" with "System.IO.StringWriter"

------------------------------
Tobias Arnold
RPA Developer
ITERGO GmbH
Europe/Duesseldorf
------------------------------

AndreyKudinov
Level 10
dt.WriteXml would output xml, but you mention that you need to feed it to soap api later, you can't just convert it to any xml and expect it to work.
You need to send xml that service expects to get, which is described in wsdl. You can probably use SoapUI to get a "template", then fill it from your collection in a loop.​

------------------------------
Andrey Kudinov
Project Manager
MobileTelesystems PJSC
Europe/Moscow
------------------------------