converting XML to hash/dict/CustomTreeCtrl

Discussion in 'Python' started by Astan Chee, Feb 1, 2010.

  1. Astan Chee

    Astan Chee Guest

    Hi,
    I have xml files that I want to convert to a hash/dict and then further
    placed in a wx CustomTreeCtrl based on the structure. The problem I am
    having now is that the XML file is very unusual and there aren't any
    unique identifiers to be put in a dict and because there are no unique
    variables, finding the value of it from a CustromTreeCtrl is abit tricky.
    I would appreciate any help or links to projects similar to this.
    Thanks

    The XML file looks something like this:
    <doc>
    <rm:statsDoc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <stats name="position1" description="Calculation statistics"
    kind="position">
    <stats name="time" description="Timing summary" kind="section">
    <string name="timersNote" description="Note:">This is the note
    on calculation times</string>
    <stats name="timers" kind="timers">

    <timer name="totaltime" description="Total time">
    <elapsed>609.081574</elapsed>
    <user>2531.972081</user>
    <system>65.119100</system>
    </timer>
    <timer name="partialTimer" description="Gravitational Displacement">
    <elapsed>1772.011230</elapsed>
    </timer>
    <stats name="subTimers" description="All non-phased time"
    kind="timers">
    <timer name="subATimer" description="Phase time A">
    <elapsed>72.418861</elapsed>
    </timer>

    <timer name="subBTimer" description="Phase time B">
    <elapsed>28.285192</elapsed>
    </timer>
    <timer name="spaceMem" description="Space memory">
    <elapsed>0.000</elapsed>
    </timer>
    </stats>
    <timer name="endTime" description="End">
    <elapsed>607.432373</elapsed>
    </timer>
    </stats>
    </stats>
    <stats name="space" description="Space usage summary" kind="section">
    <stats name="systemSpace" description="System Space">
    <memory name="heapSpace" description="Total Space">
    <peak>4833280000</peak>

    <current>4833280000</current>
    </memory>
    <memory name="spaceResidentSize" description="Space resident size">
    <peak>4182777856</peak>
    <current>4182777856</current>
    </memory>
    <int name="pageMem">1</int>

    <int name="memReclaims">1943498</int>
    <int name="memSwaps">0</int>
    </stats>
    <stats name="subsystems" kind="memstats">
    <memory name="geoSpace" description="Geo-Space">
    <peak>1640100156</peak>
    <current>411307840</current>
    </memory>
    <memory name="gridSpace" description="Grid-Space">
    <peak>709596712</peak>
    <current>1406752</current>
    </memory>
    <memory name="spaceMem" description="Space memory">
    <peak>737720720</peak>
    <current>0</current>
    </memory>
    <memory name="endTime" description="End">
    <peak>607.432373</peak>
    </memory>
    </stats>
    <memory name="subsystemSpace" description="Subsystem space
    total">
    <peak>5164184694</peak>
    <current>2054715622</current>
    </memory>

    </stats>
    </stats>
    </rm:statsDoc>
    </doc>
     
    Astan Chee, Feb 1, 2010
    #1
    1. Advertising

  2. Astan Chee, 01.02.2010 23:34:
    > I have xml files that I want to convert to a hash/dict and then further
    > placed in a wx CustomTreeCtrl based on the structure. The problem I am
    > having now is that the XML file is very unusual and there aren't any
    > unique identifiers to be put in a dict and because there are no unique
    > variables, finding the value of it from a CustromTreeCtrl is abit tricky.
    > I would appreciate any help or links to projects similar to this.


    What part of the structure and what information are you interested in? That
    will determine the key that you should use. Maybe storing more than one
    field as key is an option.

    Stefan


    > The XML file looks something like this:
    > <doc>
    > <rm:statsDoc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    > <stats name="position1" description="Calculation statistics"
    > kind="position">
    > <stats name="time" description="Timing summary" kind="section">
    > <string name="timersNote" description="Note:">This is the note on
    > calculation times</string>
    > <stats name="timers" kind="timers">
    >
    > <timer name="totaltime" description="Total time">
    > <elapsed>609.081574</elapsed>
    > <user>2531.972081</user>
    > <system>65.119100</system>
    > </timer>
    > <timer name="partialTimer" description="Gravitational Displacement">
    > <elapsed>1772.011230</elapsed>
    > </timer>
    > <stats name="subTimers" description="All non-phased time"
    > kind="timers">
    > <timer name="subATimer" description="Phase time A">
    > <elapsed>72.418861</elapsed>
    > </timer>
    >
    > <timer name="subBTimer" description="Phase time B">
    > <elapsed>28.285192</elapsed>
    > </timer>
    > <timer name="spaceMem" description="Space memory">
    > <elapsed>0.000</elapsed>
    > </timer>
    > </stats>
    > <timer name="endTime" description="End">
    > <elapsed>607.432373</elapsed>
    > </timer>
    > </stats>
    > </stats>
    > <stats name="space" description="Space usage summary" kind="section">
    > <stats name="systemSpace" description="System Space">
    > <memory name="heapSpace" description="Total Space">
    > <peak>4833280000</peak>
    >
    > <current>4833280000</current>
    > </memory>
    > <memory name="spaceResidentSize" description="Space resident size">
    > <peak>4182777856</peak>
    > <current>4182777856</current>
    > </memory>
    > <int name="pageMem">1</int>
    >
    > <int name="memReclaims">1943498</int>
    > <int name="memSwaps">0</int>
    > </stats>
    > <stats name="subsystems" kind="memstats">
    > <memory name="geoSpace" description="Geo-Space">
    > <peak>1640100156</peak>
    > <current>411307840</current>
    > </memory>
    > <memory name="gridSpace" description="Grid-Space">
    > <peak>709596712</peak>
    > <current>1406752</current>
    > </memory>
    > <memory name="spaceMem" description="Space memory">
    > <peak>737720720</peak>
    > <current>0</current>
    > </memory>
    > <memory name="endTime" description="End">
    > <peak>607.432373</peak>
    > </memory>
    > </stats>
    > <memory name="subsystemSpace" description="Subsystem space
    > total">
    > <peak>5164184694</peak>
    > <current>2054715622</current>
    > </memory>
    >
    > </stats>
    > </stats>
    > </rm:statsDoc>
    > </doc>
    >
     
    Stefan Behnel, Feb 2, 2010
    #2
    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. Skip Montanaro
    Replies:
    0
    Views:
    414
    Skip Montanaro
    Aug 15, 2003
  2. Alexander Kozlovsky

    dict!ident as equivalent of dict["ident"]

    Alexander Kozlovsky, May 21, 2006, in forum: Python
    Replies:
    5
    Views:
    360
    Alexander Kozlovsky
    May 22, 2006
  3. Paul Melis

    dict.has_key(x) versus 'x in dict'

    Paul Melis, Dec 6, 2006, in forum: Python
    Replies:
    48
    Views:
    1,322
    Kent Johnson
    Dec 15, 2006
  4. Astan Chee
    Replies:
    2
    Views:
    347
    Astan Chee
    Feb 3, 2010
  5. rp
    Replies:
    1
    Views:
    533
    red floyd
    Nov 10, 2011
Loading...

Share This Page