parsing xml with embedded csv

Discussion in 'XML' started by Pat Ford, Jan 13, 2006.

  1. Pat Ford

    Pat Ford Guest

    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?
    Pat Ford, Jan 13, 2006
    #1
    1. Advertising

  2. Pat Ford

    William Park Guest

    Pat Ford <> wrote:
    > 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 <>, 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/
    William Park, Jan 14, 2006
    #2
    1. Advertising

  3. Pat Ford

    Peter Flynn Guest

    Pat Ford wrote:
    > 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/>

    > 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
    --
    XML FAQ: http://xml.silmaril.ie/
    Peter Flynn, Jan 15, 2006
    #3
  4. Pat Ford

    Pat Ford Guest

    "Peter Flynn" <> wrote in message
    news:...
    > Pat Ford wrote:
    > > 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.

    >
    > > 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
    > --
    > XML FAQ: http://xml.silmaril.ie/


    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.
    Pat Ford, Jan 16, 2006
    #4
  5. Pat Ford

    Pat Ford Guest

    "William Park" <> wrote in message
    news:b65a6$43c88521$d8fea1de$...
    > Pat Ford <> wrote:
    > > Hi All;
    > >
    > > 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 <>, 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
    Pat Ford, Jan 16, 2006
    #5
  6. Pat Ford

    William Park Guest

    Pat Ford <> wrote:
    >
    > "William Park" <> wrote in message
    > news:b65a6$43c88521$d8fea1de$...
    > > Pat Ford <> wrote:
    > > > Hi All;
    > > >
    > > > 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 <>, 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


    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 <>, 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/
    William Park, Jan 17, 2006
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. GIMME
    Replies:
    2
    Views:
    869
    GIMME
    Feb 11, 2004
  2. Michal Mikolajczyk
    Replies:
    0
    Views:
    630
    Michal Mikolajczyk
    Feb 13, 2004
  3. Boris Kolpackov
    Replies:
    0
    Views:
    576
    Boris Kolpackov
    Mar 20, 2007
  4. Boris Kolpackov
    Replies:
    0
    Views:
    319
    Boris Kolpackov
    Mar 21, 2007
  5. Erik Wasser
    Replies:
    5
    Views:
    437
    Peter J. Holzer
    Mar 5, 2006
Loading...

Share This Page