![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| DKP Log Parser 1.4.1c (Default branch) | iBot | Software Releases - RSS News | 0 | 05-07-2008 07:00 PM |
| Text Parser | karthikn7974 | Shell Programming and Scripting | 8 | 04-22-2008 05:16 AM |
| Perl XML:Parser help | vincaStar | Shell Programming and Scripting | 0 | 03-31-2008 01:01 AM |
| string parser | flextronics | Shell Programming and Scripting | 8 | 08-28-2006 04:39 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
xml parser in perl
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 Last edited by zedex; 04-11-2008 at 05:58 AM.. |
|
||||
|
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: Code:
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;
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|