"be consistent" | |
PerlMonks |
XML Parser and certain nodes to a hashby Dr Manhattan (Beadle) |
on May 23, 2013 at 09:06 UTC ( [id://1034911]=perlquestion: print w/replies, xml ) | Need Help?? |
Dr Manhattan has asked for the wisdom of the Perl Monks concerning the following question: Hi all I am trying to parse a multi-level XML document, and then adding certain nodes to a hash. The problem is that with the many different levels I am struggling with the referencing of the nodes that I want to add This is the code I have
The XML looks like this <XML><ID>ENG20-00001740-a</ID><POS>a</POS><SYNONYM><LITERAL sense="1">in staat</LITERAL><WORD>in</WORD><WORD>staat</WORD></SYNONYM><ILR type="be_in_state">ENG20-05295659-n</ILR><ILR type="be_in_state">ENG20-04904666-n</ILR><ILR type="near_antonym">ENG20-00002062-a</ILR><DEF/><USAGE/><BCS>3</BCS><DOMAIN>quality</DOMAIN><SUMO type="=">Breathing</SUMO></SYNSET></XML><XML><ID>ENG20-00001740-v</ID><POS>v</POS><SYNONYM><LITERAL sense="1">asem</LITERAL><WORD>asem</WORD><LITERAL sense="1">respireer</LITERAL><WORD>respireer</WORD><LITERAL sense="1">asem skep</LITERAL><WORD>asem</WORD><WORD>skep</WORD><LITERAL sense="1">asemhaal</LITERAL><WORD>asemhaal</WORD></SYNONYM><ILR type="verb_group">ENG20-00002536-v</ILR><ILR type="verb_group">ENG20-00002307-v</ILR><ILR type="also_see">ENG20-00004923-v</ILR><ILR type="also_see">ENG20-00004127-v</ILR><ILR type="subevent">ENG20-00004923-v</ILR><ILR type="subevent">ENG20-00004127-v</ILR><DEF/><USAGE/><BCS>3</BCS><DOMAIN>medicine</DOMAIN><SUMO type="=">Breathing</SUMO></SYNSET></XML> I want to put all the Literal->content in a separate hash, but the problem is that there can occur more that 1. If there is more than 1 Literal->content the XML parser stores them in a array of hashes. If there is only 1 Literal->content it is simply stores as a hash. Any ideas?
Back to
Seekers of Perl Wisdom
|
|