0

My .xml data looks like this<?xml version="1.0" encoding="UTF-8"?> -<Patient SerialNumber="SM62169666" IsKeepPrivate="1" IsDataBlinded="0" Id="{D9A334A0-C15E-405A-87FD-E2B3CB172A9C}"> -<MeterReadings> <Meter Value="166" InternalTime="2014-03-20 20:54:16" DisplayTime="2014-03-20 12:53:33"/> <Meter Value="176" InternalTime="2014-03-20 21:06:46" DisplayTime="2014-03-20 13:06:03"/> <Meter Value="86" InternalTime="2014-03-21 03:24:04" DisplayTime="2014-03-20 19:23:22"/> <Meter Value="56" InternalTime="2014-03-21 10:59:35" DisplayTime="2014-03-21 02:58:52"/> <Meter Value="249" InternalTime="2014-03-22 01:21:11" DisplayTime="2014-03-21 17:20:29"/>

and its a large file that I will have to read in blocks. However, I am currently just trying to read in the first line that contains meaningful data - the Meter Value and the DisplayTime. I thought I should used textscan. I open the file and try to pull out the data as follows:

C = textscan(fid,'<Meter Value="%d " InternalTime="%s %s" DisplayTime="%s %s %*[^\n]',5,'HeaderLines',3)

I get C =

[0x1 int32]    {0x1 cell}    {0x1 cell}    {0x1 cell}    {0x1 cell}

[0x1 int32]    {0x1 cell}    {0x1 cell}    {0x1 cell}    {0x1 cell}

and, it says these cells are empty. It should be reading 5 lines of data, not just 2. And, these cells should not be empty. ??? What am I doing wrong?

1 Answers1

0

The first input for Textscan is the fileID for the file generated when you use fopen, not just the name of the file.

Try

fid = fopen('C:\Users\Bobby\Desktop\bgData.xml')
C=textscan(fid,'<Meter Value="%d " InternalTime="%s %s" DisplayTime="%s %s %*[^\n]',5,'HeaderLines',3)
fclose(fid)

There are also seems to be some issues with your formatspec itself.

  • Thanks, yeah, I tried fid first. Output confirms that it is opening and closing the file successfully. I don't know whats up with the formatting. Its supposed to remove the " – HeatherBrokeComputy Oct 02 '14 at 23:23
  • For more complex pattern matching like yours I'd suggest using tokens= regexp( str, expression, 'tokens' ) – Suneth Attygalle Oct 03 '14 at 01:19