Need help getting xml "i:type" value into node red

Hi,
I'm hoping someone can help me with a perplexing problem I'm having getting a value out of xml.I'm trying to pull specific values out of an xml document and publish them to a csv file. I've had no problem with getting values as long as they have their own xml tag: I simply walk down the xml document and pull that value (for example "Name" in a change node (after an xml node) by using jsonata as in

payload.Configuration.Workspaces[].Workspace[].Name[]

But if the value does not have a distinct xml tag, I'm having a problem getting the value, even when I use the debug mode to get the exact path.So when I try and extract the the "i:type=" value (in the example below it is "ChartElement") all I get is "i:type" as the value.

The jsonata walks down the file like this:

payload.Configuration.Workspaces[].Workspace[].Elements[].Element[]["i:type"]

Can anyone help me figure this out? I've spent a lot of time reading the web about this and have not found the solution

Here is the Element portion of the xml that is giving me a problem:

        <Element xmlns="" i:type="ChartElement">
          <Appearance>
            <BackgroundImageIndex>0</BackgroundImageIndex>
            <BackgroundImages xmlns:d7p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />
            <BorderVisibility>Default</BorderVisibility>
            <CircularGaugeOptions>
              <Layout>Full</Layout>
              <MajorTickCount>11</MajorTickCount>
              <MaxValue>100</MaxValue>
              <MinValue>0</MinValue>
              <MinorTickCount>4</MinorTickCount>
              <Style>Default</Style>
            </CircularGaugeOptions>
            <DigitalGaugeOptions>
              <DigitCount>0</DigitCount>
              <Mode>Default</Mode>
              <Style>Default</Style>
            </DigitalGaugeOptions>
            <DisplayKind>Text</DisplayKind>
            <IndicatorOptions>
              <OffColor>Off</OffColor>
              <OnColor>Green</OnColor>
            </IndicatorOptions>
            <LinearGaugeOptions>
              <MajorTickCount>11</MajorTickCount>
              <MaxValue>100</MaxValue>
              <MinValue>0</MinValue>
              <MinorTickCount>4</MinorTickCount>
              <Orientation>Vertical</Orientation>
              <Style>Default</Style>
            </LinearGaugeOptions>
            <NameAlignment>Default</NameAlignment>
            <NameBackColor i:nil="true" />
            <NameFont i:nil="true" />
            <NameForeColor i:nil="true" />
            <NameVisibility>Default</NameVisibility>
            <TextDisplayOptions>
              <FalseText i:nil="true" />
              <Precision>0</Precision>
              <TrueText i:nil="true" />
            </TextDisplayOptions>
            <ValueAlignment>Default</ValueAlignment>
            <ValueBackColor i:nil="true" />
            <ValueEnlargement i:nil="true" />
            <ValueFont i:nil="true" />
            <ValueForeColor i:nil="true" />
            <Visibility>Default</Visibility>
          </Appearance>
          <Enabled>false</Enabled>
          <Height>160</Height>
          <ID>828d1c10-e872-4cfb-baf4-465c3f18bd41</ID>
          <Name>Fermenter 1 Spunding</Name>
          <UserControl>false</UserControl>
          <Width>180</Width>
          <X>390</X>
          <Y>10</Y>
          <Channels>
            <ChartChannelOptions>
              <Appearance>
                <LineColor i:nil="true" />
              </Appearance>
              <AutoScale>true</AutoScale>
              <AxisYMax>0</AxisYMax>
              <AxisYMin>0</AxisYMin>
              <ChannelID i:nil="true" />
            </ChartChannelOptions>
            <ChartChannelOptions>
              <Appearance>
                <LineColor i:nil="true" />
              </Appearance>
              <AutoScale>true</AutoScale>
              <AxisYMax>0</AxisYMax>
              <AxisYMin>0</AxisYMin>
              <ChannelID i:nil="true" />
            </ChartChannelOptions>
          </Channels>
          <ChartAppearance>
            <HGridLines>1</HGridLines>
            <VGridLines>0</VGridLines>
          </ChartAppearance>
          <RefreshInterval>60</RefreshInterval>
          <SpanSeconds>86400</SpanSeconds>
        </Element>

Many thanks in advance for any suggestions.

Put the XML through an XML node then simply copy the path from the debug sidebar. No JSONata, no parsing just convert and grab.

OK, Thanks for your quick reply. That works and I can retrieve the value if I put in the change node
set msg. payload
msg.payload.Configuration.Workspaces[0].Workspace[0].Elements[0].Element[0].$["i:type"]

But if I want to iterate through the entire xml document (that has over 100 instanes of the "Element" section I quoted above and retrieve all the values of
<Element xmlns="" i:type="The Value I want retrieve">how do I do this?
I was successfully doing it with jsonata for the xml values above that have their own distinct xml tag, but it does not work for this case. In other words, it is working for a single node that is defined in the xml path, but if you try and treat the whole thing as an array by replacing the [0]. with []. it just hangs and throws "undefined" errors or at best I get back the quoted tag "i:type" with out the value in that tag.

What am I missing about how to do this? Do I have to do a find and replace on that specific line and then run the jsonata code on it?

I should also mention that I was planning on doing a "split" after collecting all these values and then a "join" to put them in a csv file so that all the element values I am trying to extract from each "Element" section of the xml are on the same line. But let's not get to far ahead on this, unless that somehow limits the way to approach the problem.

Thanks again for your help on this.

Once your XML is a native js object, you have various options.

Personally, due to how slow I've found it to be (and the alien format) I avoid JSONata, but it is doable.

I would use a function node and filter functions.

If you can post a snippet of the XML (a small sample, say 5 entries) and describe which elements you want, I'll show you how.

Well thank you so much! I have included a snipptet of the "Workspace" section that includes some of the "Element" sections in the quote below. What I need is the name of the Workspace and then the design parameters of each of the "Element" sections that are on that Workspace: the Type (i:type), Name, and hexadecimal ID.

with jsonata I've retrieved Workspace, Name, and ID with the following change nodes:

payload.Configuration.Workspaces[].Workspace[].Name[]
payload.Configuration.Workspaces[].Workspace[].Elements[].Element[].Name[]
payload.Configuration.Workspaces[].Workspace[].Elements[].Element[].ID[]

As I said, my problem is how to get the Type
Here is the xml snippet Starting with the Workspace and containing some of the design elements. The code above should help to locate the values I'm after in each tag.:
Many thanks for your help!

    <Workspace>
      <BackgroundImageHeight>600</BackgroundImageHeight>
      <BackgroundImagePath i:nil="true" />
      <BackgroundImageWidth>800</BackgroundImageWidth>
      <Elements>
        <Element xmlns="" i:type="ChartElement">
          <Appearance>
            <BackgroundImageIndex>0</BackgroundImageIndex>
            <BackgroundImages xmlns:d7p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />
            <BorderVisibility>Default</BorderVisibility>
            <CircularGaugeOptions>
              <Layout>Full</Layout>
              <MajorTickCount>11</MajorTickCount>
              <MaxValue>100</MaxValue>
              <MinValue>0</MinValue>
              <MinorTickCount>4</MinorTickCount>
              <Style>Default</Style>
            </CircularGaugeOptions>
            <DigitalGaugeOptions>
              <DigitCount>0</DigitCount>
              <Mode>Default</Mode>
              <Style>Default</Style>
            </DigitalGaugeOptions>
            <DisplayKind>Text</DisplayKind>
            <IndicatorOptions>
              <OffColor>Off</OffColor>
              <OnColor>Green</OnColor>
            </IndicatorOptions>
            <LinearGaugeOptions>
              <MajorTickCount>11</MajorTickCount>
              <MaxValue>100</MaxValue>
              <MinValue>0</MinValue>
              <MinorTickCount>4</MinorTickCount>
              <Orientation>Vertical</Orientation>
              <Style>Default</Style>
            </LinearGaugeOptions>
            <NameAlignment>Default</NameAlignment>
            <NameBackColor i:nil="true" />
            <NameFont i:nil="true" />
            <NameForeColor i:nil="true" />
            <NameVisibility>Default</NameVisibility>
            <TextDisplayOptions>
              <FalseText i:nil="true" />
              <Precision>0</Precision>
              <TrueText i:nil="true" />
            </TextDisplayOptions>
            <ValueAlignment>Default</ValueAlignment>
            <ValueBackColor i:nil="true" />
            <ValueEnlargement i:nil="true" />
            <ValueFont i:nil="true" />
            <ValueForeColor i:nil="true" />
            <Visibility>Default</Visibility>
          </Appearance>
          <Enabled>false</Enabled>
          <Height>160</Height>
          <ID>828d1c10-e872-4cfb-baf4-465c3f18bd41</ID>
          <Name>Fermenter 1 Spunding</Name>
          <UserControl>false</UserControl>
          <Width>180</Width>
          <X>390</X>
          <Y>10</Y>
          <Channels>
            <ChartChannelOptions>
              <Appearance>
                <LineColor i:nil="true" />
              </Appearance>
              <AutoScale>true</AutoScale>
              <AxisYMax>0</AxisYMax>
              <AxisYMin>0</AxisYMin>
              <ChannelID i:nil="true" />
            </ChartChannelOptions>
            <ChartChannelOptions>
              <Appearance>
                <LineColor i:nil="true" />
              </Appearance>
              <AutoScale>true</AutoScale>
              <AxisYMax>0</AxisYMax>
              <AxisYMin>0</AxisYMin>
              <ChannelID i:nil="true" />
            </ChartChannelOptions>
          </Channels>
          <ChartAppearance>
            <HGridLines>1</HGridLines>
            <VGridLines>0</VGridLines>
          </ChartAppearance>
          <RefreshInterval>60</RefreshInterval>
          <SpanSeconds>86400</SpanSeconds>
        </Element>
        <Element xmlns="" i:type="GlobalVariableElement">
          <Appearance>
            <BackgroundImageIndex>0</BackgroundImageIndex>
            <BackgroundImages xmlns:d7p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
              <d7p1:string></d7p1:string>
              <d7p1:string></d7p1:string>
              <d7p1:string></d7p1:string>
            </BackgroundImages>
            <BorderVisibility>Default</BorderVisibility>
            <CircularGaugeOptions>
              <Layout>Full</Layout>
              <MajorTickCount>11</MajorTickCount>
              <MaxValue>100</MaxValue>
              <MinValue>0</MinValue>
              <MinorTickCount>4</MinorTickCount>
              <Style>Default</Style>
            </CircularGaugeOptions>
            <DigitalGaugeOptions>
              <DigitCount>1</DigitCount>
              <Mode>Default</Mode>
              <Style>Default</Style>
            </DigitalGaugeOptions>
            <DisplayKind>Text</DisplayKind>
            <IndicatorOptions>
              <OffColor>Off</OffColor>
              <OnColor>Green</OnColor>
            </IndicatorOptions>
            <LinearGaugeOptions>
              <MajorTickCount>11</MajorTickCount>
              <MaxValue>100</MaxValue>
              <MinValue>0</MinValue>
              <MinorTickCount>4</MinorTickCount>
              <Orientation>Vertical</Orientation>
              <Style>Default</Style>
            </LinearGaugeOptions>
            <NameAlignment>Default</NameAlignment>
            <NameBackColor i:nil="true" />
            <NameFont i:nil="true" />
            <NameForeColor i:nil="true" />
            <NameVisibility>Default</NameVisibility>
            <TextDisplayOptions>
              <FalseText></FalseText>
              <Precision>0</Precision>
              <TrueText></TrueText>
            </TextDisplayOptions>
            <ValueAlignment>Default</ValueAlignment>
            <ValueBackColor i:nil="true" />
            <ValueEnlargement i:nil="true" />
            <ValueFont i:nil="true" />
            <ValueForeColor i:nil="true" />
            <Visibility>Default</Visibility>
          </Appearance>
          <Enabled>false</Enabled>
          <Height>160</Height>
          <ID>25cea11a-a4c6-4239-a4e0-b6e81220945b</ID>
          <Name>F1 iSpindel sg</Name>
          <UserControl>false</UserControl>
          <Width>180</Width>
          <X>570</X>
          <Y>10</Y>
          <Precision>3</Precision>
          <Value i:nil="true" />
          <VariableName i:nil="true" />
          <VariableType>String</VariableType>
        </Element>
        <Element xmlns="" i:type="DeviceElement">
          <Appearance>
            <BackgroundImageIndex>0</BackgroundImageIndex>
            <BackgroundImages xmlns:d7p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
              <d7p1:string></d7p1:string>
              <d7p1:string></d7p1:string>
              <d7p1:string></d7p1:string>
            </BackgroundImages>
            <BorderVisibility>Default</BorderVisibility>
            <CircularGaugeOptions>
              <Layout>Full</Layout>
              <MajorTickCount>11</MajorTickCount>
              <MaxValue>100</MaxValue>
              <MinValue>0</MinValue>
              <MinorTickCount>4</MinorTickCount>
              <Style>Default</Style>
            </CircularGaugeOptions>
            <DigitalGaugeOptions>
              <DigitCount>1</DigitCount>
              <Mode>Default</Mode>
              <Style>Default</Style>
            </DigitalGaugeOptions>
            <DisplayKind>Text</DisplayKind>
            <IndicatorOptions>
              <OffColor>Off</OffColor>
              <OnColor>Green</OnColor>
            </IndicatorOptions>
            <LinearGaugeOptions>
              <MajorTickCount>11</MajorTickCount>
              <MaxValue>100</MaxValue>
              <MinValue>0</MinValue>
              <MinorTickCount>4</MinorTickCount>
              <Orientation>Vertical</Orientation>
              <Style>Default</Style>
            </LinearGaugeOptions>
            <NameAlignment>Default</NameAlignment>
            <NameBackColor i:nil="true" />
            <NameFont i:nil="true" />
            <NameForeColor i:nil="true" />
            <NameVisibility>Default</NameVisibility>
            <TextDisplayOptions>
              <FalseText></FalseText>
              <Precision>0</Precision>
              <TrueText></TrueText>
            </TextDisplayOptions>
            <ValueAlignment>Default</ValueAlignment>
            <ValueBackColor i:nil="true" />
            <ValueEnlargement i:nil="true" />
            <ValueFont i:nil="true" />
            <ValueForeColor i:nil="true" />
            <Visibility>Default</Visibility>
          </Appearance>
          <Enabled>false</Enabled>
          <Height>160</Height>
          <ID>ed1c4220-ebef-4809-ad08-85773e47586b</ID>
          <Name>Duty Cycle 1</Name>
          <UserControl>false</UserControl>
          <Width>180</Width>
          <X>20</X>
          <Y>10</Y>
          <PortID>80af1784-344e-403b-b0f0-9505c5a28489</PortID>
        </Element>

Hi, the XML you posted is incomplete & does not contain the workspace name part (so I had to guess some of the formatting & fill in some blanks myself - so this may not work for you).

This is how I aproached it - hopefully it is of some help...

flow with annotations...

the results...

the flow...

[{"id":"b13c609e.cc7a3","type":"inject","z":"bcf9fb5b.eed7f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":190,"y":160,"wires":[["fddba160.17079"]]},{"id":"37e11698.e5276a","type":"xml","z":"bcf9fb5b.eed7f8","name":"xml --> js object","property":"payload","attr":"","chr":"","x":520,"y":160,"wires":[["fff724e0.66e708","c6084fa.aed5fb"]]},{"id":"fff724e0.66e708","type":"debug","z":"bcf9fb5b.eed7f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":870,"y":160,"wires":[]},{"id":"c6084fa.aed5fb","type":"function","z":"bcf9fb5b.eed7f8","name":"js object to rows","func":"/*\npayload.Configuration.Workspaces[].Workspace[].Name[]\npayload.Configuration.Workspaces[].Workspace[].Elements[].Element[].Name[]\npayload.Configuration.Workspaces[].Workspace[].Elements[].Element[].ID[]\n*/\n\nmsg.originalData = msg.payload; //save in msg (for debugging)\n\nvar workspaces = msg.payload.Workspaces.Workspace;\n\n//workspace name get name\nvar wsName = 1;\nvar rows = [];\nfor (let iWS = 0; iWS < workspaces.length; iWS++) {\n    let workspace = workspaces[iWS];\n    let elements = workspace.Elements[0].Element;\n    let workspaceName = workspace.Name[0];\n    let workspaceRows = elements.map(el => {\n        return {\n            workspace: workspaceName,\n            id:   el.ID[0],\n            name:   el.Name[0],\n            type:   el.$[\"i:type\"],\n        }\n    })\n    rows.push(...workspaceRows)\n}\nmsg.payload = rows;\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":540,"y":260,"wires":[["f49656b3.e6c808","794207fd.386fd8"]]},{"id":"f49656b3.e6c808","type":"debug","z":"bcf9fb5b.eed7f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":870,"y":260,"wires":[]},{"id":"fddba160.17079","type":"template","z":"bcf9fb5b.eed7f8","name":"the XML","field":"payload","fieldType":"msg","format":"text","syntax":"plain","template":"<Workspaces>\n    <Workspace>\n        <BackgroundImageHeight>600</BackgroundImageHeight>\n        <BackgroundImagePath i:nil=\"true\" />\n        <BackgroundImageWidth>800</BackgroundImageWidth>\n        <Name>workspace1</Name>\n        <Elements>\n            <Element\n                xmlns=\"\" i:type=\"ChartElement\">\n                <Appearance>\n                    <BackgroundImageIndex>0</BackgroundImageIndex>\n                    <BackgroundImages\n                        xmlns:d7p1=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\" />\n                        <BorderVisibility>Default</BorderVisibility>\n                        <CircularGaugeOptions>\n                            <Layout>Full</Layout>\n                            <MajorTickCount>11</MajorTickCount>\n                            <MaxValue>100</MaxValue>\n                            <MinValue>0</MinValue>\n                            <MinorTickCount>4</MinorTickCount>\n                            <Style>Default</Style>\n                        </CircularGaugeOptions>\n                        <DigitalGaugeOptions>\n                            <DigitCount>0</DigitCount>\n                            <Mode>Default</Mode>\n                            <Style>Default</Style>\n                        </DigitalGaugeOptions>\n                        <DisplayKind>Text</DisplayKind>\n                        <IndicatorOptions>\n                            <OffColor>Off</OffColor>\n                            <OnColor>Green</OnColor>\n                        </IndicatorOptions>\n                        <LinearGaugeOptions>\n                            <MajorTickCount>11</MajorTickCount>\n                            <MaxValue>100</MaxValue>\n                            <MinValue>0</MinValue>\n                            <MinorTickCount>4</MinorTickCount>\n                            <Orientation>Vertical</Orientation>\n                            <Style>Default</Style>\n                        </LinearGaugeOptions>\n                        <NameAlignment>Default</NameAlignment>\n                        <NameBackColor i:nil=\"true\" />\n                        <NameFont i:nil=\"true\" />\n                        <NameForeColor i:nil=\"true\" />\n                        <NameVisibility>Default</NameVisibility>\n                        <TextDisplayOptions>\n                            <FalseText i:nil=\"true\" />\n                            <Precision>0</Precision>\n                            <TrueText i:nil=\"true\" />\n                        </TextDisplayOptions>\n                        <ValueAlignment>Default</ValueAlignment>\n                        <ValueBackColor i:nil=\"true\" />\n                        <ValueEnlargement i:nil=\"true\" />\n                        <ValueFont i:nil=\"true\" />\n                        <ValueForeColor i:nil=\"true\" />\n                        <Visibility>Default</Visibility>\n                    </Appearance>\n                    <Enabled>false</Enabled>\n                    <Height>160</Height>\n                    <ID>828d1c10-e872-4cfb-baf4-465c3f18bd41</ID>\n                    <Name>Fermenter 1 Spunding</Name>\n                    <UserControl>false</UserControl>\n                    <Width>180</Width>\n                    <X>390</X>\n                    <Y>10</Y>\n                    <Channels>\n                        <ChartChannelOptions>\n                            <Appearance>\n                                <LineColor i:nil=\"true\" />\n                            </Appearance>\n                            <AutoScale>true</AutoScale>\n                            <AxisYMax>0</AxisYMax>\n                            <AxisYMin>0</AxisYMin>\n                            <ChannelID i:nil=\"true\" />\n                        </ChartChannelOptions>\n                        <ChartChannelOptions>\n                            <Appearance>\n                                <LineColor i:nil=\"true\" />\n                            </Appearance>\n                            <AutoScale>true</AutoScale>\n                            <AxisYMax>0</AxisYMax>\n                            <AxisYMin>0</AxisYMin>\n                            <ChannelID i:nil=\"true\" />\n                        </ChartChannelOptions>\n                    </Channels>\n                    <ChartAppearance>\n                        <HGridLines>1</HGridLines>\n                        <VGridLines>0</VGridLines>\n                    </ChartAppearance>\n                    <RefreshInterval>60</RefreshInterval>\n                    <SpanSeconds>86400</SpanSeconds>\n                </Element>\n                <Element\n                    xmlns=\"\" i:type=\"GlobalVariableElement\">\n                    <Appearance>\n                        <BackgroundImageIndex>0</BackgroundImageIndex>\n                        <BackgroundImages\n                            xmlns:d7p1=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">\n                            <d7p1:string></d7p1:string>\n                            <d7p1:string></d7p1:string>\n                            <d7p1:string></d7p1:string>\n                        </BackgroundImages>\n                        <BorderVisibility>Default</BorderVisibility>\n                        <CircularGaugeOptions>\n                            <Layout>Full</Layout>\n                            <MajorTickCount>11</MajorTickCount>\n                            <MaxValue>100</MaxValue>\n                            <MinValue>0</MinValue>\n                            <MinorTickCount>4</MinorTickCount>\n                            <Style>Default</Style>\n                        </CircularGaugeOptions>\n                        <DigitalGaugeOptions>\n                            <DigitCount>1</DigitCount>\n                            <Mode>Default</Mode>\n                            <Style>Default</Style>\n                        </DigitalGaugeOptions>\n                        <DisplayKind>Text</DisplayKind>\n                        <IndicatorOptions>\n                            <OffColor>Off</OffColor>\n                            <OnColor>Green</OnColor>\n                        </IndicatorOptions>\n                        <LinearGaugeOptions>\n                            <MajorTickCount>11</MajorTickCount>\n                            <MaxValue>100</MaxValue>\n                            <MinValue>0</MinValue>\n                            <MinorTickCount>4</MinorTickCount>\n                            <Orientation>Vertical</Orientation>\n                            <Style>Default</Style>\n                        </LinearGaugeOptions>\n                        <NameAlignment>Default</NameAlignment>\n                        <NameBackColor i:nil=\"true\" />\n                        <NameFont i:nil=\"true\" />\n                        <NameForeColor i:nil=\"true\" />\n                        <NameVisibility>Default</NameVisibility>\n                        <TextDisplayOptions>\n                            <FalseText></FalseText>\n                            <Precision>0</Precision>\n                            <TrueText></TrueText>\n                        </TextDisplayOptions>\n                        <ValueAlignment>Default</ValueAlignment>\n                        <ValueBackColor i:nil=\"true\" />\n                        <ValueEnlargement i:nil=\"true\" />\n                        <ValueFont i:nil=\"true\" />\n                        <ValueForeColor i:nil=\"true\" />\n                        <Visibility>Default</Visibility>\n                    </Appearance>\n                    <Enabled>false</Enabled>\n                    <Height>160</Height>\n                    <ID>25cea11a-a4c6-4239-a4e0-b6e81220945b</ID>\n                    <Name>F1 iSpindel sg</Name>\n                    <UserControl>false</UserControl>\n                    <Width>180</Width>\n                    <X>570</X>\n                    <Y>10</Y>\n                    <Precision>3</Precision>\n                    <Value i:nil=\"true\" />\n                    <VariableName i:nil=\"true\" />\n                    <VariableType>String</VariableType>\n                </Element>\n                <Element\n                    xmlns=\"\" i:type=\"DeviceElement\">\n                    <Appearance>\n                        <BackgroundImageIndex>0</BackgroundImageIndex>\n                        <BackgroundImages\n                            xmlns:d7p1=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">\n                            <d7p1:string></d7p1:string>\n                            <d7p1:string></d7p1:string>\n                            <d7p1:string></d7p1:string>\n                        </BackgroundImages>\n                        <BorderVisibility>Default</BorderVisibility>\n                        <CircularGaugeOptions>\n                            <Layout>Full</Layout>\n                            <MajorTickCount>11</MajorTickCount>\n                            <MaxValue>100</MaxValue>\n                            <MinValue>0</MinValue>\n                            <MinorTickCount>4</MinorTickCount>\n                            <Style>Default</Style>\n                        </CircularGaugeOptions>\n                        <DigitalGaugeOptions>\n                            <DigitCount>1</DigitCount>\n                            <Mode>Default</Mode>\n                            <Style>Default</Style>\n                        </DigitalGaugeOptions>\n                        <DisplayKind>Text</DisplayKind>\n                        <IndicatorOptions>\n                            <OffColor>Off</OffColor>\n                            <OnColor>Green</OnColor>\n                        </IndicatorOptions>\n                        <LinearGaugeOptions>\n                            <MajorTickCount>11</MajorTickCount>\n                            <MaxValue>100</MaxValue>\n                            <MinValue>0</MinValue>\n                            <MinorTickCount>4</MinorTickCount>\n                            <Orientation>Vertical</Orientation>\n                            <Style>Default</Style>\n                        </LinearGaugeOptions>\n                        <NameAlignment>Default</NameAlignment>\n                        <NameBackColor i:nil=\"true\" />\n                        <NameFont i:nil=\"true\" />\n                        <NameForeColor i:nil=\"true\" />\n                        <NameVisibility>Default</NameVisibility>\n                        <TextDisplayOptions>\n                            <FalseText></FalseText>\n                            <Precision>0</Precision>\n                            <TrueText></TrueText>\n                        </TextDisplayOptions>\n                        <ValueAlignment>Default</ValueAlignment>\n                        <ValueBackColor i:nil=\"true\" />\n                        <ValueEnlargement i:nil=\"true\" />\n                        <ValueFont i:nil=\"true\" />\n                        <ValueForeColor i:nil=\"true\" />\n                        <Visibility>Default</Visibility>\n                    </Appearance>\n                    <Enabled>false</Enabled>\n                    <Height>160</Height>\n                    <ID>ed1c4220-ebef-4809-ad08-85773e47586b</ID>\n                    <Name>Duty Cycle 1</Name>\n                    <UserControl>false</UserControl>\n                    <Width>180</Width>\n                    <X>20</X>\n                    <Y>10</Y>\n                    <PortID>80af1784-344e-403b-b0f0-9505c5a28489</PortID>\n                </Element>\n            </Elements>\n        </Workspace>\n        <Workspace>\n            <BackgroundImageHeight>600</BackgroundImageHeight>\n            <BackgroundImagePath i:nil=\"true\" />\n            <BackgroundImageWidth>800</BackgroundImageWidth>\n            <Name>workspace2</Name>\n            <Elements>\n                <Element\n                    xmlns=\"\" i:type=\"ChartElement\">\n                    <Appearance>\n                        <BackgroundImageIndex>0</BackgroundImageIndex>\n                        <BackgroundImages\n                            xmlns:d7p1=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\" />\n                            <BorderVisibility>Default</BorderVisibility>\n                            <CircularGaugeOptions>\n                                <Layout>Full</Layout>\n                                <MajorTickCount>11</MajorTickCount>\n                                <MaxValue>100</MaxValue>\n                                <MinValue>0</MinValue>\n                                <MinorTickCount>4</MinorTickCount>\n                                <Style>Default</Style>\n                            </CircularGaugeOptions>\n                            <DigitalGaugeOptions>\n                                <DigitCount>0</DigitCount>\n                                <Mode>Default</Mode>\n                                <Style>Default</Style>\n                            </DigitalGaugeOptions>\n                            <DisplayKind>Text</DisplayKind>\n                            <IndicatorOptions>\n                                <OffColor>Off</OffColor>\n                                <OnColor>Green</OnColor>\n                            </IndicatorOptions>\n                            <LinearGaugeOptions>\n                                <MajorTickCount>11</MajorTickCount>\n                                <MaxValue>100</MaxValue>\n                                <MinValue>0</MinValue>\n                                <MinorTickCount>4</MinorTickCount>\n                                <Orientation>Vertical</Orientation>\n                                <Style>Default</Style>\n                            </LinearGaugeOptions>\n                            <NameAlignment>Default</NameAlignment>\n                            <NameBackColor i:nil=\"true\" />\n                            <NameFont i:nil=\"true\" />\n                            <NameForeColor i:nil=\"true\" />\n                            <NameVisibility>Default</NameVisibility>\n                            <TextDisplayOptions>\n                                <FalseText i:nil=\"true\" />\n                                <Precision>0</Precision>\n                                <TrueText i:nil=\"true\" />\n                            </TextDisplayOptions>\n                            <ValueAlignment>Default</ValueAlignment>\n                            <ValueBackColor i:nil=\"true\" />\n                            <ValueEnlargement i:nil=\"true\" />\n                            <ValueFont i:nil=\"true\" />\n                            <ValueForeColor i:nil=\"true\" />\n                            <Visibility>Default</Visibility>\n                        </Appearance>\n                        <Enabled>false</Enabled>\n                        <Height>160</Height>\n                        <ID>828d1c10-e872-4cfb-baf4-465c3f18bd41</ID>\n                        <Name>Fermenter 1 Spunding</Name>\n                        <UserControl>false</UserControl>\n                        <Width>180</Width>\n                        <X>390</X>\n                        <Y>10</Y>\n                        <Channels>\n                            <ChartChannelOptions>\n                                <Appearance>\n                                    <LineColor i:nil=\"true\" />\n                                </Appearance>\n                                <AutoScale>true</AutoScale>\n                                <AxisYMax>0</AxisYMax>\n                                <AxisYMin>0</AxisYMin>\n                                <ChannelID i:nil=\"true\" />\n                            </ChartChannelOptions>\n                            <ChartChannelOptions>\n                                <Appearance>\n                                    <LineColor i:nil=\"true\" />\n                                </Appearance>\n                                <AutoScale>true</AutoScale>\n                                <AxisYMax>0</AxisYMax>\n                                <AxisYMin>0</AxisYMin>\n                                <ChannelID i:nil=\"true\" />\n                            </ChartChannelOptions>\n                        </Channels>\n                        <ChartAppearance>\n                            <HGridLines>1</HGridLines>\n                            <VGridLines>0</VGridLines>\n                        </ChartAppearance>\n                        <RefreshInterval>60</RefreshInterval>\n                        <SpanSeconds>86400</SpanSeconds>\n                    </Element>\n                    <Element\n                        xmlns=\"\" i:type=\"GlobalVariableElement\">\n                        <Appearance>\n                            <BackgroundImageIndex>0</BackgroundImageIndex>\n                            <BackgroundImages\n                                xmlns:d7p1=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">\n                                <d7p1:string></d7p1:string>\n                                <d7p1:string></d7p1:string>\n                                <d7p1:string></d7p1:string>\n                            </BackgroundImages>\n                            <BorderVisibility>Default</BorderVisibility>\n                            <CircularGaugeOptions>\n                                <Layout>Full</Layout>\n                                <MajorTickCount>11</MajorTickCount>\n                                <MaxValue>100</MaxValue>\n                                <MinValue>0</MinValue>\n                                <MinorTickCount>4</MinorTickCount>\n                                <Style>Default</Style>\n                            </CircularGaugeOptions>\n                            <DigitalGaugeOptions>\n                                <DigitCount>1</DigitCount>\n                                <Mode>Default</Mode>\n                                <Style>Default</Style>\n                            </DigitalGaugeOptions>\n                            <DisplayKind>Text</DisplayKind>\n                            <IndicatorOptions>\n                                <OffColor>Off</OffColor>\n                                <OnColor>Green</OnColor>\n                            </IndicatorOptions>\n                            <LinearGaugeOptions>\n                                <MajorTickCount>11</MajorTickCount>\n                                <MaxValue>100</MaxValue>\n                                <MinValue>0</MinValue>\n                                <MinorTickCount>4</MinorTickCount>\n                                <Orientation>Vertical</Orientation>\n                                <Style>Default</Style>\n                            </LinearGaugeOptions>\n                            <NameAlignment>Default</NameAlignment>\n                            <NameBackColor i:nil=\"true\" />\n                            <NameFont i:nil=\"true\" />\n                            <NameForeColor i:nil=\"true\" />\n                            <NameVisibility>Default</NameVisibility>\n                            <TextDisplayOptions>\n                                <FalseText></FalseText>\n                                <Precision>0</Precision>\n                                <TrueText></TrueText>\n                            </TextDisplayOptions>\n                            <ValueAlignment>Default</ValueAlignment>\n                            <ValueBackColor i:nil=\"true\" />\n                            <ValueEnlargement i:nil=\"true\" />\n                            <ValueFont i:nil=\"true\" />\n                            <ValueForeColor i:nil=\"true\" />\n                            <Visibility>Default</Visibility>\n                        </Appearance>\n                        <Enabled>false</Enabled>\n                        <Height>160</Height>\n                        <ID>25cea11a-a4c6-4239-a4e0-b6e81220945b</ID>\n                        <Name>F1 iSpindel sg</Name>\n                        <UserControl>false</UserControl>\n                        <Width>180</Width>\n                        <X>570</X>\n                        <Y>10</Y>\n                        <Precision>3</Precision>\n                        <Value i:nil=\"true\" />\n                        <VariableName i:nil=\"true\" />\n                        <VariableType>String</VariableType>\n                    </Element>\n                    <Element\n                        xmlns=\"\" i:type=\"DeviceElement\">\n                        <Appearance>\n                            <BackgroundImageIndex>0</BackgroundImageIndex>\n                            <BackgroundImages\n                                xmlns:d7p1=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">\n                                <d7p1:string></d7p1:string>\n                                <d7p1:string></d7p1:string>\n                                <d7p1:string></d7p1:string>\n                            </BackgroundImages>\n                            <BorderVisibility>Default</BorderVisibility>\n                            <CircularGaugeOptions>\n                                <Layout>Full</Layout>\n                                <MajorTickCount>11</MajorTickCount>\n                                <MaxValue>100</MaxValue>\n                                <MinValue>0</MinValue>\n                                <MinorTickCount>4</MinorTickCount>\n                                <Style>Default</Style>\n                            </CircularGaugeOptions>\n                            <DigitalGaugeOptions>\n                                <DigitCount>1</DigitCount>\n                                <Mode>Default</Mode>\n                                <Style>Default</Style>\n                            </DigitalGaugeOptions>\n                            <DisplayKind>Text</DisplayKind>\n                            <IndicatorOptions>\n                                <OffColor>Off</OffColor>\n                                <OnColor>Green</OnColor>\n                            </IndicatorOptions>\n                            <LinearGaugeOptions>\n                                <MajorTickCount>11</MajorTickCount>\n                                <MaxValue>100</MaxValue>\n                                <MinValue>0</MinValue>\n                                <MinorTickCount>4</MinorTickCount>\n                                <Orientation>Vertical</Orientation>\n                                <Style>Default</Style>\n                            </LinearGaugeOptions>\n                            <NameAlignment>Default</NameAlignment>\n                            <NameBackColor i:nil=\"true\" />\n                            <NameFont i:nil=\"true\" />\n                            <NameForeColor i:nil=\"true\" />\n                            <NameVisibility>Default</NameVisibility>\n                            <TextDisplayOptions>\n                                <FalseText></FalseText>\n                                <Precision>0</Precision>\n                                <TrueText></TrueText>\n                            </TextDisplayOptions>\n                            <ValueAlignment>Default</ValueAlignment>\n                            <ValueBackColor i:nil=\"true\" />\n                            <ValueEnlargement i:nil=\"true\" />\n                            <ValueFont i:nil=\"true\" />\n                            <ValueForeColor i:nil=\"true\" />\n                            <Visibility>Default</Visibility>\n                        </Appearance>\n                        <Enabled>false</Enabled>\n                        <Height>160</Height>\n                        <ID>ed1c4220-ebef-4809-ad08-85773e47586b</ID>\n                        <Name>Duty Cycle 1</Name>\n                        <UserControl>false</UserControl>\n                        <Width>180</Width>\n                        <X>20</X>\n                        <Y>10</Y>\n                        <PortID>80af1784-344e-403b-b0f0-9505c5a28489</PortID>\n                    </Element>\n                </Elements>\n            </Workspace>\n        </Workspaces>    ","output":"str","x":340,"y":160,"wires":[["37e11698.e5276a"]]},{"id":"794207fd.386fd8","type":"csv","z":"bcf9fb5b.eed7f8","name":"","sep":",","hdrin":"","hdrout":"all","multi":"mult","ret":"\\n","temp":"workspace,id,name,type","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":730,"y":360,"wires":[["b4f12783.0dc248"]]},{"id":"b4f12783.0dc248","type":"debug","z":"bcf9fb5b.eed7f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":870,"y":360,"wires":[]},{"id":"de3c6f38.9a12","type":"comment","z":"bcf9fb5b.eed7f8","name":"____Faking the XML ___","info":"","x":270,"y":120,"wires":[]},{"id":"3c993294.d9cf6e","type":"comment","z":"bcf9fb5b.eed7f8","name":"Convert to JS object","info":"","x":530,"y":120,"wires":[]},{"id":"233f7e4b.3d69f2","type":"comment","z":"bcf9fb5b.eed7f8","name":"Convert JS object to rows","info":"","x":530,"y":300,"wires":[]},{"id":"f4562179.50b9c","type":"comment","z":"bcf9fb5b.eed7f8","name":"Convert rows to CSV","info":"","x":780,"y":400,"wires":[]}]

Wow. Thank you so much! I'm sorry that I didn't upload the entire file, but it was so large that I thought I would deliver the relevant parts and you could give me some guidance--I didn't expect that you would provide a full solution, but you did.

The part that was missing I changed in line 9 of your "js object to rows" function:

var workspaces = msg.payload.Configuration.Workspaces[0].Workspace;

Here is how I used what you sent to figure it out: Apparently the function needed an address to get to the first instance of the iterating through the loop. That was missing because the Configuration section was not in the part I sent you, so the script you sent kept giving me an error about not being able to find "Workspace" of "undefined". When I put in "Configuration" in the line above it then gave me an error of not being able to find the "length" of "undefined". So when I walked down the script (from the msg.payload of the XML node to "Workspace" and used the debug tool to find the path, it gave me a path with the [0] inserted after Workspaces and when I put that in--the script worked.
Can't thank you enough for writing a symphony after I sent you just a few bars of the music!
I really need to learn how to use the function node and this has given me a template to study.
All the best.

2 Likes

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