How to add attributes to an element?


I have a document and I would like to add attributes to one of the elements.

After converting the document to a string (using documentToXMLString) it looks like this:

but I want it to look like this:
<request attribute1=“111” attribute2=“222”>

How would I add attribute1 and attribute2 to the request element?

Any help would be appreciated.



Do you know the attributes which you need to add at design time or would it be decided at runtime ? because if you already know the attributes you can simply create two document types(one with attributes and one without) and add a map step after initial XML conversion and map the values in the second document which has attributes.

Hi JP,

Add the elements attribute1 and attribute2 as Strings with prefix ‘@’ in their names under the request document. Such as

You can map values to these fields as usual. When you convert this into XML they will appear as attributes to request.

1 Like

Perfect. Thanks.