parsing xml with embedded csv

P

Pat Ford

Hi All;
I'm working on a data acquisition system, the system runs on Linux, and the
config files are Xml like.

eg
<CHANNELS>
<META>
Short Label,textbox,width=5,Alpha,required
Long Label,textbox,width=15,Alpha,required
Crate,select,1,2
Channel,textbox,width=5,Numeric,Min=0,Max=9999
ESP flag,checkbox
RMS flag,checkbox
Rate LS,select,1,10,100,1000
Rate HS,select,1,10,100,1000
Cal Factor,textbox,width=7,Numeric
Zero offset,textbox,width=7,Numeric
Exc. Voltage,textbox,width=7,Numeric
Amp Gain,select,1,10,20,50,100,200,500,1000
LP filter,select,1=10Hz,2=100Hz,3=1KHz
RMS gain,select,1,10,20,50,100
PS#,select,1,2,3,4,5
DIN#,special,type=din
</META>
<FIELDNAMES>
Short Label,Long Label,Crate,Channel,ESP flag,RMS flag,Rate LS,Rate HS,Cal
Factor,Zero offset,Exc. Voltage,Amp Gain,LP filter,RMS gain,PS#,DIN#
</FIELDNAMES>
<DATA>
TM,TM,0,142,,,1,,0.00046566,0,1,1,0,1,77,0
--,--,0,143,,,1,,30.5176,0,1,1,0,1,77,0
P0,P0,0,4042,,,1,,30.5176,0,1,1,0,1,77,6204
TP,TP,0,231,,,1,,30,-0.12976,1,1,0,1,77,0
LF,LF,0,224,,,1,,41.666,-10.194,1,1,0,1,77,0
FP,FP,0,226,,,1,,5.0505,-333.97,1,1,0,1,77,0
</DATA>
</CHANNELS>

Using libxml, I've parsed out the fields using the tree1 example, but I
can't figure out how to rewind the stream, so I can start looking for a
different block. I have ~12 programs that need to access different blocks so
I'm thinking I'll make a parser.lib, but I need a way to rewind.
Any ideas?
 
W

William Park

Pat Ford said:
Hi All;
I'm working on a data acquisition system, the system runs on Linux, and the
config files are Xml like.

eg
<CHANNELS>
<META>
Short Label,textbox,width=5,Alpha,required
Long Label,textbox,width=15,Alpha,required
Crate,select,1,2
Channel,textbox,width=5,Numeric,Min=0,Max=9999
ESP flag,checkbox
RMS flag,checkbox
Rate LS,select,1,10,100,1000
Rate HS,select,1,10,100,1000
Cal Factor,textbox,width=7,Numeric
Zero offset,textbox,width=7,Numeric
Exc. Voltage,textbox,width=7,Numeric
Amp Gain,select,1,10,20,50,100,200,500,1000
LP filter,select,1=10Hz,2=100Hz,3=1KHz
RMS gain,select,1,10,20,50,100
PS#,select,1,2,3,4,5
DIN#,special,type=din
</META>
<FIELDNAMES>
Short Label,Long Label,Crate,Channel,ESP flag,RMS flag,Rate LS,Rate HS,Cal
Factor,Zero offset,Exc. Voltage,Amp Gain,LP filter,RMS gain,PS#,DIN#
</FIELDNAMES>
<DATA>
TM,TM,0,142,,,1,,0.00046566,0,1,1,0,1,77,0
--,--,0,143,,,1,,30.5176,0,1,1,0,1,77,0
P0,P0,0,4042,,,1,,30.5176,0,1,1,0,1,77,6204
TP,TP,0,231,,,1,,30,-0.12976,1,1,0,1,77,0
LF,LF,0,224,,,1,,41.666,-10.194,1,1,0,1,77,0
FP,FP,0,226,,,1,,5.0505,-333.97,1,1,0,1,77,0
</DATA>
</CHANNELS>

Using libxml, I've parsed out the fields using the tree1 example, but I
can't figure out how to rewind the stream, so I can start looking for a
different block. I have ~12 programs that need to access different blocks so
I'm thinking I'll make a parser.lib, but I need a way to rewind.
Any ideas?

I don't quite get "rewinding". How is it different from just reading
the file again?

--
William Park <[email protected]>, Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
http://freshmeat.net/projects/bashdiff/
 
P

Peter Flynn

Pat said:
Hi All;
I'm working on a data acquisition system, the system runs on Linux, and the
config files are Xml like.

eg
<CHANNELS>
<META>
Short Label,textbox,width=5,Alpha,required
Long Label,textbox,width=15,Alpha,required
[...]

Eww. Looks like someone just wrapped the original data in tags and hoped
for the best. said:
Using libxml, I've parsed out the fields using the tree1 example, but I
can't figure out how to rewind the stream, so I can start looking for a
different block. I have ~12 programs that need to access different blocks so
I'm thinking I'll make a parser.lib, but I need a way to rewind.

The concept doesn't exist in XML processing. If you use a language like
XSLT you can address any location in the document at any time, so you
can write templates which perform the various tests you require.

///Peter
 
P

Pat Ford

Peter Flynn said:
Pat said:
Hi All;
I'm working on a data acquisition system, the system runs on Linux, and the
config files are Xml like.

eg
<CHANNELS>
<META>
Short Label,textbox,width=5,Alpha,required
Long Label,textbox,width=15,Alpha,required
[...]

Eww. Looks like someone just wrapped the original data in tags and hoped
for the best. <sigh/>

The lusers, opps I mean users have insisted that they keep the interface to
the data system windows based. I don't do windows, so a web based interface
was crafted. We need flexibility, so the meta block defines how the
interface for that block will look, the fieldnames describe what is in each
column ( we can add new fields anywhere in the form as new features creap
in), then the config data is csv. It boils down to legacy users, legacy
format and multiple OS and programming environments.
The concept doesn't exist in XML processing. If you use a language like
XSLT you can address any location in the document at any time, so you
can write templates which perform the various tests you require.

///Peter

I'm hoping to have a function along the lines of;
float getIntField ( char* blockName, char* fieldname, int line)
float getFloatField ( char* blockName, char* fieldname, int line)
char* getStringField ( char* blockName, char* fieldname, int line)
....
I'm pretty much constrained to that ugly file format.
 
P

Pat Ford

William Park said:
I don't quite get "rewinding". How is it different from just reading
the file again?

--
William Park <[email protected]>, Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
http://freshmeat.net/projects/bashdiff/

I cant figure oput how to reread the file without closing it and reopening
it. I don't feel safe doing that because it would open the possibility that
someone could save a change between the close and open. I was hoping I could
either do something like ungetc, or rewind so the file stays locked by the
current user. This is on a system that camn have several engineers and a
tunnel controler all jockeying for position. Engineers around here don't
always wait their turns.
Is there a way using libxml to return to the start of the file and search
the tree again for a different set of data?
Pat
 
W

William Park

Pat Ford said:
I cant figure oput how to reread the file without closing it and reopening
it. I don't feel safe doing that because it would open the possibility that
someone could save a change between the close and open. I was hoping I could
either do something like ungetc, or rewind so the file stays locked by the
current user. This is on a system that camn have several engineers and a
tunnel controler all jockeying for position. Engineers around here don't
always wait their turns.
Is there a way using libxml to return to the start of the file and search
the tree again for a different set of data?
Pat

How about temporary file, or reading the file into memory? If you're at
C level, you can do rewind(3) which is a frontend for fseek(3).

--
William Park <[email protected]>, Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
http://freshmeat.net/projects/bashdiff/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top