Re: read XML with IDL [message #71750 is a reply to message #71672] |
Thu, 15 July 2010 01:41  |
sh
Messages: 26 Registered: April 2010
|
Junior Member |
|
|
On Jul 14, 9:16 pm, Karl <karl.w.schu...@gmail.com> wrote:
> On Jul 14, 7:58 am, kBob <krd...@gmail.com> wrote:
>
>
>
>
>
>> On Jul 14, 3:59 am, sh <sebastian.h...@gmail.com> wrote:
>
>>> Hello together,
>
>>> I already searched in the archive, but I didn't find a clear answer.
>
>>> Every time you want to read .xml files, you have to write your own
>>> parser (e.g. .edit xml_to_struct__define.pro) right?
>
>>> But is there a possibilty to build up a struct automatically? E.g. the
>>> input .xml file
>
>>> <Solar_System>
>>> <Planet NAME='Mercury'>
>>> <Orbit UNITS='kilometers' TYPE='ulong64'>579100000</Orbit>
>>> <Period UNITS='days' TYPE='float'>87.97</Period>
>>> <Satellites TYPE='int'>0</Satellites>
>>> </Planet>
>>> ...
>>> </Solar_System>
>
>>> output in IDL (structs within a "main" struct) the name of struct and
>>> tags depends on the name of elements and the attributes
>
>>> solar_system={solar_system,planet:{planet,orbit:
>>> {orbit,units:'kilometers',type:'ulong64',value:'579100000'}, period:
>>> {period,units:'days',type:'float',value:'87.97'},satellites:
>>> {satellites,type:'int',value:'0'}}}
>
>>> print, solar_system.planet.orbit
>>> { kilometers ulong64 579100000}
>
>>> print, solar_system.planet.orbit.value
>>> 579100000
>
>>> My questions are now: Should I write my own parser? Should I wait for
>>> IDL8, maybe there are more adv. features for XML? Or does someone have
>>> already such a routine?
>
>>> thanks,
>>> Sebastian
>
>> Have you looked into xml_to_struct__define.pro example provided with
>> the IDL distribution?
>
>> I would think you have, as ths Solar System XML is the example they
>> use to turn into a structure.
>
>> IDL Help provides a tutorial for this example code.
>
>> Kelly Dean
>> Fort Collins, CO
>
> IDLffXMLSAX
> and
> IDLffXMLDOM
>
> are two XML parsers that come with IDL. I think that the SAX parser
> would help here.
Yes I know these 2.
But you have to overwrite some methods of the SAX parser to make use
of it for a certain xml file.
And I didn't want to write everytime a new xml_to_struct__define.pro!
Therefore I asked if there is a "general" solution to take the
elements/node/attributes names within a xml file to generate a
structur, like in my example above. Because in this case I have only
one parser who generates the output structure with a dependency on the
xml elements/node/attributes names and I can read every xml file!
|
|
|