Reformatting a simple XML file

Dayvan CowboyDayvan Cowboy Registered User
edited November 2009 in Help / Advice Forum
I have a simple XML file with the following format:
<data>
  <group id="group1">
    <upper>
      <item id="A">
        <stage age="1 Week">
          <property1>1</property1>
          <property2>AC</property2>
        </stage>
      </item>
    </upper>
    <lower>
      <item id="A">
        <stage age="1 Week">
          <property1>2</property1>
          <property2>AN</property2>
        </stage>
      </item>
    </lower>
  </group>
</data>

Each 'item' contains about 30 'stages', each 'upper'/'lower' contains around 15 'items', and the document contains 2 'groups', so it's a pretty sizeable bit of data. I've been told that in order to speed up searching through this data (incidentally, if it makes any difference, I'm using Actionscript to search through it), I should be using attributes for 'property1' and 'property2', not child elements.

So, I have two questions:
1) Will it really speed things up a lot? At the moment, I'm having to compare about 50 user input values to each value in the XML, and looping through it all can take up to 40 seconds.

2) Is there a program available that can easily change the code above into something like this:
<data>
  <group id="group1">
    <upper>
      <item id="A">
        <stage age="1 Week" property1 = "1" property2 = "AC" />
      </item>
    </upper>
    <lower>
      <item id="A">
        <stage age="1 Week" property1 = "2" property2 = "AN" />
      </item>
    </lower>
  </group>
</data>

It seems like this should be a fairly simple thing to automate, so I'm hoping there's something out there. I've done some googling and found out about XSLT, but I literally just learned that it exists this morning so I'm not in a place where I know how to use it (yet).

Any help would be greatly appreciated.

Dayvan Cowboy on

Posts

  • GanluanGanluan Registered User regular
    edited November 2009
    XSLT will actually do exactly what you want, although it does take a little while to learn the syntax. You apply the transform from the XSLT to the XML, and it will create a new XML document based on the transformation rules.

    This would also be very simple to write in something like .NET - are you looking for an already existing app or curious about how to write it yourself?

    As for your speed question - XML performance varies significantly between programming technologies, and even then between different implementations. What are you using for searching right now?

    Ganluan on
  • Dayvan CowboyDayvan Cowboy Registered User
    edited November 2009
    For now, I really just want something premade to get this thing done. I'll have a look at the XSLT stuff on W3C and see what I can do, thanks.

    As for what I'm using, the XML is being imported into a flash file, where I'm using E4X in Actionscript 3 to process the thing.

    Dayvan Cowboy on
  • LewishamLewisham Registered User regular
    edited November 2009
    For now, I really just want something premade to get this thing done.

    Never heard of such a thing: that's what XSLT is for (except it's a bitch to learn)

    Lewisham on
  • SeguerSeguer Registered User regular
    edited November 2009
    Are the properties actual attributes of something, or are they literally property1, 2, 3, 4 etc? Attributes would be something like:

    <person name="John" age="26" gender="Male" />

    Seguer on
  • Dayvan CowboyDayvan Cowboy Registered User
    edited November 2009
    Yeah, I should have said - they're actually attributes, the example was just for the structure of the document. Looks like I'll be diving headfirst into some XSLT at work tomorrow.

    Dayvan Cowboy on
Sign In or Register to comment.