1

Let me first say that I am new to programming and XML, and I am open to any support the community can offer me.

Background: I am writing my own XML parsing script in Matlab to support a project in which real time data processing is essential. I have no issue loading and parsing 'non-real time' XML files. The issue I am having is with real-time XML files. The error produced is: XML document structures must start and end within the same entity.

Explanation: I am using a proprietary software to produce these real time XML files. When I click the 'generate real time XML data' button on the data acquisition program. It generates two files in my chosen directory. The first, is xml_smf (which is zero bytes and I cannot open). The second, is an xml file which grows in size over time (as real time data is acquired and placed into the xml file).

The issue with this real time XML file is that they do not contain closing tags, thus throwing the 'XML document structures must start and end within the same entity' error. When I click the 'stop generating real time XML data' button on my data acquisition program. The xml_smf file disappears, and the xml file is finally updated with closing tags. The issue is that I need the program to read the data in real time, without the field user having to constantly click stop/start button on the data acquisition program.

My question(s) are as follows:

  1. Does anyone have experience with XML_SMF files? Any suggestions on what they might be used for?

  2. Is there a work around I can apply in Matlab, to open the XML file and append it with the proper closing tags?

  3. Do you have any recommendations for a workflow by which real time data may be processed (in Matlab)? I am picturing some kind of loop where the ever-larger XML file is re processed every 30 seconds or so.

halfer
  • 19,824
  • 17
  • 99
  • 186
J. Will
  • 13
  • 1
  • 3

1 Answers1

0

Until the file is well-formed, it's not XML. If its only issue is a missing close tag for the root element, simply read the file as text and write it out with the missing closing tag. (Hopefully you won't also have to contend with the file being held open for writing by another process.) Then read it as XML. If there are more problems, see How to parse invalid (bad / not well-formed) XML?

kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • Thank you for your feedback, kjhughes. Open/Read/Write(append)/Close would certainly be a feasible workaround for dealing with pesky open tags. I imagine there are 'cleaner' ways of reading real time data, but there is something to be said for 'learning the hard way'. – J. Will Jul 12 '17 at 21:10
  • @J.Will: if there are any problems with a process holding the (bad) XML file open, you could copy it to a temporary file, repair it there, and then read it as XML. Repeat every time the bad XML file is updated. – halfer Aug 02 '17 at 10:28
  • 1
    @halfer: Thanks allot, that sounds like a good idea, I'll try it. – J. Will Aug 02 '17 at 16:31