The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-28-2008
zedex zedex is offline
Registered User
  
 

Join Date: Feb 2007
Location: india,mumbai
Posts: 138
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..
  #2 (permalink)  
Old 03-29-2008
cbkihong cbkihong is offline Forum Advisor  
Advisor
  
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,624
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;
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:54 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0