# Build an XML file

**URL:** <https://discourse.nodered.org/t/build-an-xml-file/25370>\
**Category:** General\
**Created:** [23 April 2020 16:00 UTC](https://discourse.nodered.org/t/build-an-xml-file/25370 "2020-04-23T16:00:25Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![caveman](https://avatars.discourse-cdn.com/v4/letter/c/58956e/32.png) [@caveman](https://discourse.nodered.org/u/caveman)\
**Post date:** [23 April 2020 16:00 UTC](https://discourse.nodered.org/t/build-an-xml-file/25370/1 "2020-04-23T16:00:25Z")

</div>

Hi all,

it is maybe an simple topic but i have not found an solution... maybe i have not read very well the doc...

i need to build an xml file that have this structure:

```auto
<?xml version="1.0" ?>
  <pcis:PCISDocument xmlns:picsis="urn:global:pcis:xsd:1" xmlns:ns1="r" schemaVersion="1.5" creationDate="2016-11-08T09:52:55.075Z">
     <EISBody>
        <EventList>
            <ObjectEvent>
                <eventTime>2020-04-15T10:49:15.440Z</eventTime>
                <eventTimeZoneOffset>+01:00</eventTimeZoneOffset>
                <baseExtension>
                    <eventID>urn:uuid:5ede43e1-77ae-4e8b-8a04-e8303666ea34</eventID>
                </baseExtension>
                <picsList>
                    <pics>urn:pics:id:ai:0x1000ABBA0019A524</pics>
                    <pics>urn:pics:id:ai:0x1000ABBA0002067E</pics>
                    <pics>urn:pics:id:in:0x1000ABBA0011242C</pics>
                </picsList>
                <action>EXECUTE</action>
                <bizStep>urn:picsglobal:cbv:bizstep:cycle_counting</bizStep>
                <bizLocation>
                    <id>urn:pics:id:ln:4047111.09401.5</id>
                </bizLocation>
            </ObjectEvent>
        </EventList>
    </EISBody>
</pcis:PCISDocument>

```

i can build the as an array of objects like this:

```auto
[{"data":"0x1400ABBA002224BD"},{"data":"0x4500000000A93C00000000070002000024C3A6EA"},{"data":"0x1000ABBA0019A524"},{"data":"0x1000ABBA0023323D"},{"data":"0x1000ABBA002442DA"},{"data":"0x1000ABBA0010340D"},{"data":"0x1400ABBA002114DE"},{"data":"0x1000ABBA0002067E"},{"data":"0x1000ABBA0003165F"},{"data":"0x1000ABBA000466B8"},{"data":"0x1000ABBA0012144F"},{"data":"0x1000ABBA001564A8"},{"data":"0x1000ABBA0011242C"},{"data":"0x1000ABBA000756DB"},{"data":"0x1000ABBA0009B715"},{"data":"0x300034180080F8603018066132F2FF56"},{"data":"0x1000ABBA0020025E"},{"data":"0x1000ABBA001744EA"},{"data":"0x1000ABBA0001361D"}]

```

but i need to add `<eventTime>` , `<bizLocation>` (variable) and `<action>` and `<bizStep>` (static).  
tried a few methods by replacing, joning, ... but none was successful is there any "simple" way to combine with node red?

tx.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [23 April 2020 16:11 UTC](https://discourse.nodered.org/t/build-an-xml-file/25370/2 "2020-04-23T16:11:47Z")

</div>

One approach would be to take that example XML and pass it through the XML node to get it's JavaScript object equivalent. That will give you a structure to aspire to so that the XML node will convert it back the other way to get the result you want.

---

<div class="post-metadata">

**Author:** ![caveman](https://avatars.discourse-cdn.com/v4/letter/c/58956e/32.png) [@caveman](https://discourse.nodered.org/u/caveman)\
**Post date:** [27 April 2020 10:49 UTC](https://discourse.nodered.org/t/build-an-xml-file/25370/3 "2020-04-27T10:49:03Z")

</div>

Hi Nick,

thanks for the idea with the xml node... unfortunately the resulting structure is pretty complex and i do not know how to build it ...(tried but no real result ...)

 ![Bildschirmfoto vom 2020-04-27 12-44-38](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/1/01c19c0d8993ab6f480b2e9ad493aef5bbf547bb.png)  
any suggestion ... ?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [27 April 2020 11:24 UTC](https://discourse.nodered.org/t/build-an-xml-file/25370/4 "2020-04-27T11:24:01Z")

</div>

you could get a head start by doing this...

1. in the debug window, click the `payload` item - then click the middle icon on the right  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/d/0d4a205cf01890714a8674531670d0f1e6ac6edc.png)

2. in an inject node (set for JSON), then paste what you copied. (you can edit out values you dont want/or need)

3. wire that inject to a function node 9or change node if you wish) to edit / replace parts etc.

e.g.

inject JSON (pasted JSON) --\> change node --\> XML --\> debug node

---

<div class="post-metadata">

**Author:** ![caveman](https://avatars.discourse-cdn.com/v4/letter/c/58956e/32.png) [@caveman](https://discourse.nodered.org/u/caveman)\
**Post date:** [27 April 2020 11:43 UTC](https://discourse.nodered.org/t/build-an-xml-file/25370/5 "2020-04-27T11:43:57Z")

</div>

Hi Steve,

i am not sure i get it ...

my problem is to get an array of objects of an array of objects of an ....how can i build an loop that give me such an structure .... ?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [27 April 2020 12:42 UTC](https://discourse.nodered.org/t/build-an-xml-file/25370/6 "2020-04-27T12:42:56Z")

</div>

Did you try what I said?

Once you have a base object you can add and remove parts of it THEN transform back to XML ready to generate an XML file

isn't that your final goal here?

I do realise an inject might not be what you want or need in the end - but to get started, do that.

Once you have a handle on playing with static data (adding array elements etc) then you can migrate what you learn into an automated solution.

> [@caveman](#):
>
> how can i build an loop that give me such an structure

Anyone can show you how to do a loop. But you can't even build the required object....

> [@caveman](#):
>
> unfortunately the resulting structure is pretty complex and i do not know how to build it

So, I'm trying to help you break this huge seemingly insurmountable problem into small solvable tasks.

---

<div class="post-metadata">

**Author:** ![caveman](https://avatars.discourse-cdn.com/v4/letter/c/58956e/32.png) [@caveman](https://discourse.nodered.org/u/caveman)\
**Post date:** [23 June 2020 10:37 UTC](https://discourse.nodered.org/t/build-an-xml-file/25370/7 "2020-06-23T10:37:28Z")

</div>

Hi all,

thanks for your suggestions. Finaly i solved as recommended by cutting in small pieces 🙂 ... even if that (it should be an interface ...) is not needed any more ... well i see it as learning... wow! what an tool... Thanks to all that are helping to develop such an tool.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [7 July 2020 10:37 UTC](https://discourse.nodered.org/t/build-an-xml-file/25370/8 "2020-07-07T10:37:30Z")

</div>

Closed on 7 July 2020 10:37 UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
