hi all i want to read xml file in perl i am using XML::Simple for this. i am not getting how to read following file
removing xml file due to some reason
hi all i want to read xml file in perl i am using XML::Simple for this. i am not getting how to read following file
removing xml file due to some reason
If you don't mind me suggesting an alternative module or approach to tackle your question, consider learning XPath if you are serious about parsing complicated XML documents (of course the XML document must be a valid one). This is because XPath allows you to condense a moderately complex set of matching criteria into a string that succinctly specifies what you are looking for.
I recommend LibXML for parsing. It is fast with demonstrated accuracy and good conformance to specifications, that is comparable to many famous Java ones (say, Xerces J), and I consider that's practically the only one that is good enough for use from within Perl. Of course, you must install the module and LibXML first (on many Linux system for instance precompiled packages are shipped with most distributions):
Petr Pajas / XML-LibXML-1.66 - search.cpan.org
I saved your document provided as test.xml and the following 5 lines of code directly gives me "ORCL". To save time I omitted all error checking code but please don't mimic for anything more productional:
use XML::LibXML;
use XML::LibXML::XPathContext;
my $doc = XML::LibXML->new()->parse_file('test.xml');
my $xp = XML::LibXML::XPathContext->new($doc);
print [$xp->findnodes('//REGION[@ID="A2"]//DETAIL/@ORACLE_SID')]->[0]->value;