03-25-2011 04:51 AM
Hi,
I have created a string (in xml style by using string constants, loops, and values) and now want to embed this into an already prepared XML file under certain element without changing the schema of the XML file to LV schema. Any idea how exactly do this?
Rgds,
David
03-25-2011 04:59 AM
Use the standard file functions - read in the string, find the place when you want to place your new string, shove it in and write it back to the file.
03-25-2011 05:12 AM
Could you elaborate more on how to write back without applying LV schema (an example)?
03-25-2011 05:59 AM
You use the standard file functions, not the XML ones. I'm assuming the example finder (Help>>Find Examples) should have some examples of using those.
03-25-2011 10:00 AM
Thanks, I managed to add the string but now the tricky part is to have certain bytes (Set File position), easy way to get that?
03-25-2011 01:14 PM
What exactly do you mean by "have certain bytes (Set File position)"?
If you have the new string just do as tst said - just use the Write to Text File function.
03-25-2011 04:24 PM
Permit me to defend the honor of the built-in functions. I have used regexes and the file functions to slice and dice many an XML file, but it can be quite fragile code and sometimes a bit ugly to find the right spot to insert your string. The following snippet "loads" an XML file (it is actually a string for simplicity here) and also takes in a string representing a new chunk of XML. I then use an XPath expression to find the right place to insert the new section, in this example the new text is inserted before the specified node, or at the end if the XPath expression is not found. The XML functions are a bit like the .NET functions, it looks unwieldy until you get used to them.
Just modify the code to load and save the existing file, and change the XPath expression to find the insertion point.
03-25-2011 04:54 PM
I would go with the build in xml parser (not the same as labview schema vis). These are probably more efficient and scalable then rolling your own parser.
03-25-2011 04:54 PM
Like the example from darin
03-30-2011 05:58 AM
To smercurio_fc and Darin
I wanted it in after a certain element in the XML file, therefore, should specify it, in case of using Write to Text file, by number of bytes. However, now I'm tryinh out the approach suggested by Darin. All the difficulties raise because I have to use a certain XML schema which different from LV schema!
Rgds,
David