ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Add attributes to existing XML elements in XML-File

Solved!
Go to solution

Hi,

I would like to "flatten" existing XML-Files with many "TestStep"-entries, from "old" to "new", by incorporating the Child-Entries "Attr" as an attribute into the normal entries.

old:

<TestReport

  <TestExecution

     <TestSteps>

        <TestStep measid="0220_0005" status="Passed">
              <Attr name="Infotext [Out]" type="String" value="[Request] 22 E0 68"/>
              <Attr name="Requirements" type="String" value="HighVariant" />
        </TestStep>

    <TestExecution

<TestReport

 

new:

<TestReport

  <TestExecution

     <TestSteps>

        <TestStep measid="0220_0005" status="Passed" Infotext="[Request] 22 E0 68" Requirements="HighVariant" />
        </TestStep>

    <TestExecution

<TestReport

 

I tried many approaches, but whenever i try to append an created "attribute" into an existing node LabView gives me an error.

 

Can anyone give me a hint?

 

This Code gives me Errorcode "-2607" 

Add_Attribute.jpg

0 Kudos
Message 1 of 7
(3,566 Views)

Here the VI (LV 2017) - but it does not work as mentioned above 🙂

0 Kudos
Message 2 of 7
(3,565 Views)
Solution
Accepted by Jo__Ho

Hi Jo,

 

Use method "Set Attribute" from class "Element":

raphschru_2-1695661654139.png

 

What you were trying to do may not work because XML attributes are unordered.

 

Regards,

Raphaël.

 

Message 3 of 7
(3,547 Views)

Hi Raphaël,

thank you so much for your extremly fast reply!

Your VI i worked perfectly - this is exactly what i needed!

 

I would have never come to the idea to use "force Type" -  i didn't even know that it existed 🙂

0 Kudos
Message 4 of 7
(3,489 Views)

Hi Raphaël,

 

Like Jo said - this coerce trick is great!  How did you create the Element Refnum?

 

David

0 Kudos
Message 5 of 7
(1,901 Views)

Hi David,

 

Coerce XML Reference to Element Class.gif

 

Regards,

Raphaël.

Message 6 of 7
(1,887 Views)

Thanks! Fast and awsome 🙂

0 Kudos
Message 7 of 7
(1,881 Views)