Changing element values in an XML file - am I missing something?

Hello evvvveryone.

I am trying something I thought was very simple, but I am somehow missing the final step. Im trying to edit a few values in an xml file and save it again.

I have an .xml-style file from another software, which i am loading with reader and then use AsElement to get the Xelements. From there I can use GetElements with an XPath in my case it is:

/OCS_1_0_30_Scene/Node/childgraph/NodeGraph/nodes/Node7/parameters/filename

then i use Element (XML Split) and filename to split the filename and add a string to it. Thats all i need to do. Element (XML Join) to get it to an Xelement again.

And then? I know i can then use AsString to make it a file again and use Writer. Thats fine. But i need to join it with the rest of the XML somehow.

I just want to look for an element, change it, and save the resulting (edited) XML file?

I have looked at the documentation and forum, but its always about either just retrieving data from xml or writing an entire xml file.

Thanks for any help. Armin.

You can Element (Split) and Element (Join) your way through the complete XML structure and replace something at the appropriate position.

If you just want to change one element which is deeply nested, you will either have to write a small plugin for that (which takes a XPath and a new Element to place at the found position) or just replace in string form with a RegEx, without converting to XElement first.

Thanks for clearing things up a little bit herbst.

I have tried the first tactic Element (Split) and Element (Join), but the problem I am having is the “replace something at the appropriate position” - that’s the part I don’t understand how to do.

So i use Split first to get to the level i want - 7 levels down. Then I use getSlice on the value spread, followed by setSlice after the transformation of the value. Then I use element join - 7 levels up. Connect the name spreads and value spreads of the rest and boooom… I get red Element nodes and memory leak in vvvv. Goes to 1.5gb then crashes. I wanted to attach the patch, but couldnt.

Plugin writing is not something i can do. Anyone fancy making a rudimentary SetElement plugin?

The RegEx string route just seems like a hack to me. I would ideally like to replace other elements too, so it would be a shame to disregard the beautiful xml structure. Using regex would also be quite difficult, because the tag i need to change is just called “filename” and there is a lot of those.

If anyone can help that would be much appreciated. At least a working example of Element(Split) and Element (join). They both dont have a help patch. :(

Ok, managed to save the patch in an earlier state.

The .ocs file is xml formated. I can do everything up to change what i want but the Element (Join) is a mystery to me. When i do it the way it would make sense to me vvvv crashes.

read_write_ocs.zip (26.1 kB)

Here is a quick Plugin which can probably do that, but I haven’t tested any spreading behaviour etc. etc., so don’t expect it to work like a node should work. Having the same amount of queries as XElements put into could work, though :).

proof of concept, probably not production-ready (9.0 kB)