in reply to Re^3: XML::Simple--dealing with a variable element
in thread XML::Simple--dealing with a variable element

Let's say for a given <dataschema> that one of the <attribute> stanza attributes is 'category'. Within that given <dataschema>, all 'category' names are unique. Some of those 'category' names, however, will appear in other <dataschema> stanza's 'category' names.

Does that make sense? Does that change the code at all? Have I made you so dizzy that you can't get off the floor?
  • Comment on Re^4: XML::Simple--dealing with a variable element

Replies are listed 'Best First'.
Re^5: XML::Simple--dealing with a variable element
by rhesa (Vicar) on Jul 26, 2006 at 23:19 UTC
    I think I'd need to see more of your data to answer that conclusively. I wrote up a little test script (if only to keep my own sanity, hehe), and that showed me I did get the attribute names according to how I understand your data. Let me know where your real stuff differs.
    use XML::Simple; $data = XMLin( \*DATA, KeepRoot => 1 ); @attrs = map { keys %{ $_->{attributes}{attribute} } } values %{ $data->{dataschemas}{dataschema} }; print "@attrs"; __DATA__ <dataschemas> <dataschema name="varyingName1"> <attributes> <attribute> <one>1</one> <two>2</two> </attribute> </attributes> </dataschema> <dataschema name="varyingName2"> <attributes> <attribute> <three>3</three> <four>4</four> </attribute> </attributes> </dataschema> </dataschemas>

    Prints: one two three four

      Here's a snippet of one of the <attributes> stanzas:

      <attributes>
      <attribute category="" parser="CSVParser" />
      <attribute category="APS" internalCategory="aps" />
      <attribute category="ASC" internalCategory="asc" />
      <attribute category="ASMT" internalCategory="asmt" />
      <attribute category="LE" internalCategory="l&e" />
      <attribute category="NCO" internalCategory="nco" />
      <attribute category="NEED TITLE" internalCategory="need title" />
      <attribute category="New Need ID" internalCategory="need id" />
      <attribute category="SUMMARY OF DELIVERABLES" parser="TextParser" extract="true" segmentation="hard" />
      </attributes>