Build an XML file

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:

<?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:

[{"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.

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.

1 Like

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 ...)


any suggestion ... ?

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

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

    That will give you the structure that you can use as a starting point.

  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

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 .... ?

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.

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

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

Hi all,

thanks for your suggestions. Finaly i solved as recommended by cutting in small pieces :slight_smile: ... 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.

2 Likes