From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
03-09-2016 02:12 PM
Seems like I may be overcomplicating things. I created a vi that can read an xml file that I manually created but also need to edit element values.
For example i want to edit element "Count" from 4 to 5 in this xml file:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<RuntimeData>
<Extruder>
<Date>3-2-2015</Date>
<Count>4</Count>
<Position>984</Position>
</Extruder>
</RuntimeData>
Any help or direction is appriciated (besides being referred to W3Schools which was my first resort)
Thanks
Jeremy
Solved! Go to Solution.
03-09-2016 02:18 PM - edited 03-09-2016 02:20 PM
I believe you need to use the value property
03-09-2016 02:31 PM
I really do think you need to check out the W3Schools for XPath info, makes life easy:
03-09-2016 03:07 PM
Darin,
You are probably right about checking out W3Schools more but that wasnt my problem. Since i dont use Labview on a day to day basis, i failed to remember that I can change the property of the node from "Read" to "Write" ... a big DUH!!!
I knew it was something simple!
Thanks for your feedback!!! Much appriciated
Jeremy
01-15-2019 07:48 AM - edited 01-15-2019 07:50 AM
Hello,
This post is the solution to my problem but I can't seem to adapt it to my VI.
I would like to:
1- Read the value of an element from my xml file (works)
2- Replace by new value (doesn't work)
3 - Read the value again (works)
The input is an xml file that has its own scheme (xsd file). Can this be the reason the property node 'set value' isn't working?
The xml file and xsd file couldn't be attached. Sorry for the screen shots...
Thanks for any help,
PS:
XML content:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?><UserVars_xml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="UserVars.xsd">
<UserVars name="495B_FT_RF">
<UserVar name="RFmeasureCurrent1">
<Default>D1</Default>
<Type>T1</Type>
<Measure>m1</Measure>
</UserVar>
<UserVar name="RFmeasureCurrent2">
<Default>d2</Default>
<Type>t2</Type>
<Measure>m2</Measure>
</UserVar>
<UserVar name="RFmeasureCurrent3">
<Default>d3</Default>
<Type>T3</Type>
<Measure>m3</Measure>
</UserVar>
</UserVars>
</UserVars_xml>
XSD CONTENT:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="UserVars_xml">
<xs:element name="UserVars">
<xs:complexType>
<xs:sequence>
<xs:element name="UserVar" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Default" type="xs:string"/>
<xs:element name="Type" type="xs:string"/>
<xs:element name="Measure" type="xs:string"/>
</xs:sequence>
<xs:attribute name="name" type="xs:string"></xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="name" type="xs:string"></xs:attribute>
</xs:complexType>
</xs:element>
</xs:element>
</xs:schema>
01-15-2019 07:21 PM
The issue is that the text string you want to place is not the value of the node you have found, but the value of a text node (which is a child). If you look at the code for the VI "Get Node Text Content" you will see where the text comes from. Here is a screenshot showing a way to do it, but you would need to be sure there was only one child node (you could delete all children first, and then add a new child node)
01-16-2019 03:17 AM
This works (the value after editing element is the right one) but the document isn't updated. Can you help me on this?
I guess I should be using "Replace Child Node", but I can't seem to make it work.
Thanks for your help and your quick answer,
01-16-2019 07:43 PM
Well if you mean the xml file is not updated, you need to write it out again using the "Save" function on the XML parser pallete. If that is not the issue, please post the code that is not working.
01-17-2019 02:41 AM - edited 01-17-2019 02:53 AM
ok that works, thanks !