I am trying to write some code that replaces some XML in a file. The first part works (opening the file, locating the XML, replacing it). When I save the file, it contains the original XML not the modified XML.
I used the Get XML method to retrieve the text I wanted to change, Setting the Value property of the node doesn't seem to work but I don't know what else to try - I need the equivalent of a 'Set XML' invoke node but I haven't found it.
Any ideas? Am I even close?
(I'm new to XML and manipulating it in LabVIEW and I'm glazing over now so ideas which don't involve reading another 20 documents would be really appreciated, thank you )
You are taking a roundabout way to changing that value.
In the meantime, I will not tell you to read 20 documents, but really, learn about XPath and Get First/All Matched Node. I am still smacking my head uncontrollably from the sight of getting the XML text simply to do string matching. I still can not unsee it....
In your case '1' is not the value of the node you found, the first child of that node is a text node with value '1'. You get used to it.
Thanks Darrin.K and PiDi,
I looked at using that method but I didn't manage to get a clear understanding of how to use XPath. I found an article which looked simple at first sight but I couldn't get the hang of how the structure of my real XML mapped onto the XPath elements. And I never managed to get anything back unless I supplied * as a search pattern.
Anyway - I'll try this method again and see if I can a guide that helps me more (easily!)
If you'll follow detailed help of Get First Matched Node VI, you'll eventually find this document: http://www.w3.org/TR/xpath/ . To do most of the common searches examples from the beginning of chapter 2 are more than sufficient 😉
Thank you! (I used Darin's code but only because I got to it first)
So now I have a node for which the XML is modified. I thought saving this to a new file would give me a duplicate of the original file but with a replaced property value...... but no! My new file contains the old XML despite 'Get XML' displaying the correct version.
Is there something different I should do?
[ This snippet reveals my true motives! ]
It seems that there is error in XML Save function, which does not save updated XML. See this topic: http://forums.ni.com/t5/LabVIEW/Save-XML-File-Error/td-p/1555028 - and follow Darins suggestion from two years back again 😉