Hi Parag, On Tuesday 11 May 2010 08:50:21 Parag Kalra wrote: > Hey All, > > I am trying to design some scripts using the module - XML::Parser > > To start learning I have a very basic scenario. Suppose I have following > XML file: > > <root> > <tag1>My Tag1</tag1> > <tag2>My Tag2</tag2> > <tag3>My Tag3</tag3> > </root> > > I want to save the the tags as the keys of a Hash and respective content as > the value of that hash > > So for the above XML file using the module XML::Parser, I would like to > create a hash having following key/value pair: > > my %my_hash = ( > tag1 => 'My Tag1', > tag2 => 'My Tag2', > tag3 => 'My Tag3', > ); > > Is that possible? >
It is possible with XML::Parser, but you really should be using one of the many XML-LibXML interfaces instead. If you can afford to read the entire file into memory as DOM, then you can use XPath and DOM functions to easily get everything: * http://www.zvon.org/xxl/XPathTutorial/General/examples.html * http://www.xml.com/pub/a/2001/11/14/xml-libxml.html If your XML is too large to be used with DOM (and you should verify it first, because you shouldn't optimise prematurely), then you can use the XML-LibXML pull parser. Regards, Shlomi Fish -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ What Makes Software Apps High Quality - http://shlom.in/sw-quality God considered inflicting XSLT as the tenth plague of Egypt, but then decided against it because he thought it would be too evil. Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] http://learn.perl.org/
