Document Tag to Store XML File

I have not used the document tag type yet. Wondering if it would be appropriate to use it to store XML file data.

If yes:

  1. How would I read/write the document tag?
  2. Is the resulting document tag able to be read and parsed by python?

If no:

  1. What would be the best route to store an XML file as part of the gateway (i.e. not read from the gateway's file system).

The intention here would be to have a download current/upload new XML document button on a page to get the current XML document tag(s) or write a new XML file to the document tag. And then, of course do something on the gateway with that XML file.

No.

  1. Parse the XML into a DOM, and then, for each node make a dictionary holding a type value, an attributes dictionary, and a nested nodes list. Save that into the document tag instead--it will be jsonified.

Good luck.

"Document" should have been "JSON". I'll upset myself if I get into why it's called "Document" instead of "JSON" too much, just know I argued against it :smiling_face_with_tear:

5 Likes

Sounds like I'll need it.

What's a DOM ?

Document Object Model. There should be some native java libraries for dealing with these.

In this case the XML files will be consistently formatted.

Maybe another option would be to parse the XML on upload into a string array tag? Is there a limitation to the length of a string? - might run into that.

1 Like

Considering that one example file in it's entirety is 548k characters, I'm probably safe I would be safe if the tag was one string. An array of strings maybe not.

Does a string array tag have the same 268,435,455 byte limitation?

I'm guessing you are actively doing something with the XML file that prevents you from storing it in the db as blob?

2 Likes

Don't put these into string tags.

XML documents this size should remain as files.

2 Likes

Yes.

I will read in portions of the XML file, make substitutions and then ultimately make a new XML file for export based on the imported file.

Definitely keep it as a file. On upload, transfer a backup copy to somewhere on the gateway filesystem (we made a folder that only Ignition can touch), and then read it into memory to start making changes.

After you're done, you can delete the file or retain it for a period of time.

2 Likes