Sponsored Content
Top Forums Shell Programming and Scripting Random XML Parsing - using Perl Post 302452016 by durden_tyler on Wednesday 8th of September 2010 11:52:55 PM
Old 09-09-2010
If the regex pattern of interest lies in a single line, then:

Code:
$ 
$ 
$ cat sample.xml
<?xml version="1.0" encoding="UTF-8"?>
<reference>
<refbody>
<section>
<p>
<ul>
<li><xref href="file1.dita#anchor" /></li>
<li><xref href="file2.dita#anchor" /></li>
</ul>
</p>
</section>
<section>
<p>
<xref href="file3.dita#anchor" />
</p>
<p>
<xref href="file4.dita#anchor" />
</p>
</section>
</refbody>
</reference>
$ 
$ 
$ perl -lne '/^.*(href=".*").*$/ && print $1' sample.xml
href="file1.dita#anchor"
href="file2.dita#anchor"
href="file3.dita#anchor"
href="file4.dita#anchor"
$ 
$ 

tyler_durden

Last edited by durden_tyler; 09-09-2010 at 12:59 AM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

xml parsing error in perl

******************PERL VERSION************************ This is perl, v5.8.1 built for i386-linux-thread-multi ERROR!!!!---Undefined subroutine &main::start called at /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi/XML/Parser/Expat.pm line 469. *********************PERL... (1 Reply)
Discussion started by: bishweshwar
1 Replies

2. Shell Programming and Scripting

Perl parsing compared to Ksh parsing

#! /usr/local/bin/perl -w $ip = "$ARGV"; $rw = "$ARGV"; $snmpg = "/usr/local/bin/snmpbulkget -v2c -Cn1 -Cn2 -Os -c $rw"; $snmpw = "/usr/local/bin/snmpwalk -Os -c $rw"; $syst=`$snmpg $ip system sysName sysObjectID`; sysDescr.0 = STRING: Cisco Internetwork Operating System Software... (1 Reply)
Discussion started by: popeye
1 Replies

3. Shell Programming and Scripting

XML Parsing

Hi, Need a script to parse the following xml file content <tag1 Name="val1"> <abc Name="key"/> <abc Name="pass">*********</abc> </tag1> <tag2 Name="Core"> <Host Name="a.b.c"> <tag1 Name="abc"> <abc Name="ac">None</abc> ... (4 Replies)
Discussion started by: Mavericc
4 Replies

4. Shell Programming and Scripting

Bash XML Parsing using Perl XPath

I have a bash script that needs to read input from an XML file, which includes varying numbers of a certain type of child node. I want to be able to iterate through all the child nodes of a given parent. I installed the Perl XML-XPath package from search.cpan.org. Once it's installed, from bash,... (4 Replies)
Discussion started by: jfmorales
4 Replies

5. Shell Programming and Scripting

Parsing XML

Learned People, Hello ! Till today, for the most part, all of the tricky questions/situations that I encountered were already posted by other folks and all I had to do was peruse through these one at a time and I could find some sort of an answer and all I had to do was add some minor tweaks... (5 Replies)
Discussion started by: ManoharMa
5 Replies

6. UNIX for Advanced & Expert Users

XML Parsing

I had a big XML and from which I have to make a layout as below *TOTAL+CB | *CB+FX | CS |*IR | *TOTAL | -------------------------------------------------------------------------------------------------- |CB FX | | | | DMFXNY EMSGFX... (6 Replies)
Discussion started by: manas_ranjan
6 Replies

7. Shell Programming and Scripting

parsing XML result by using perl?

for some reasons, i need to parse the XML result by using perl. for instance, this is a sample XML result: <Response> <status>success</status> <answer>AAA::AAA</answer> <answer>BBB::BBB</answer> </Response> then i can use this way : my @output = (); foreach my $parts (@all) ##@all... (2 Replies)
Discussion started by: tiger2000
2 Replies

8. Shell Programming and Scripting

Help in parsing XML output file in perl.

Hi I have an XML output like : <?xml version="1.0" encoding="ISO-8859-1" ?> - <envelope> - <body> - <outputGetUsageSummary> - <usgSumm rerateDone="5"> - <usageAccum accumId="269" accumCaptn="VD_DP_AR" inclUnits="9999999.00" inclUnitsUsed="0.00" shared="false" pooled="false"... (7 Replies)
Discussion started by: rkrish
7 Replies

9. Shell Programming and Scripting

XML: parsing of the Google contacts XML file

I am trying to parse the XML Google contact file using tools like xmllint and I even dived into the XSL Style Sheets using xsltproc but I get nowhere. I can not supply any sample file as it contains private data but you can download your own contacts using this script: #!/bin/sh # imports... (9 Replies)
Discussion started by: ripat
9 Replies

10. Shell Programming and Scripting

XML parsing

I have an xml file where the format looks like below <SESSIONCOMPONENT REFOBJECTNAME ="pre_session_command" REUSABLE ="NO" TYPE ="Pre-session command"> <TASK DESCRIPTION ="" NAME ="pre_session_command" REUSABLE ="NO" TYPE ="Command" VERSIONNUMBER ="1"> ... (8 Replies)
Discussion started by: r_t_1601
8 Replies
XML::Atom::Atompub(3pm) 				User Contributed Perl Documentation				   XML::Atom::Atompub(3pm)

NAME
XML::Atom::Atompub - Extensions of XML::Atom for the Atom Publishing Protocol SYNOPSIS
use XML::Atom::Entry; use XML::Atom::Feed; use XML::Atom::Atompub; my $entry = XML::Atom::Entry->new; # <app:edited>2007-01-01T00:00:00Z</app:edited> $entry->edited('2007-01-01T00:00:00Z'); # <app:control><app:draft>yes</app:draft></app:control> my $control = XML::Atom::Control->new; $control->draft('yes'); $entry->control($control); # <content type="image/png" src="http://example.com/foo.png"/> my $content = XML::Atom::Content->new; $content->type('image/png'); $content->src('http://example.com/foo.png'); $entry->content($content); # <link rel="alternate" href="http://example.com/foo.html"/> $entry->alternate_link('http://example.com/foo.html'); my $feed = XML::Atom::Feed->new; # <link rel="self" href="http://example.com"/> $feed->self_link('http://example.com'); METHODS of XML::Atom Some elements are introduced by the Atom Publishing Protocol, which are imported into XML::Atom by this module. $entry->control([ $control ]) Returns an XML::Atom::Control object representing the control of the Entry, or "undef" if there is no control. If $control is supplied, it should be an XML::Atom::Control object representing the control. For example: my $control = XML::Atom::Control->new; $control->draft('yes'); $entry->control($control); $entry->edited([ $edited ]) Returns an atom:edited element. If $edited is given, sets the atom:edited element. $content->src([ $src ]) Returns a value of src attribute in atom:content element. If $src is given, the src attribute is added. $atom->alternate_link([ $href ]) Returns a value of href attribute in atom:link element with a link relation of alternate. If $href is given, an atom:link element with a link relation of alternate is added. $atom->self_link([ $href ]) Returns a value of href attribute in atom:link element with a link relation of self. If $href is given, an atom:link element with a link relation of self is added. $atom->edit_link([ $href ]) Returns a value of href attribute in atom:link element with a link relation of edit. If $href is given, an atom:link element with a link relation of edit is added. $atom->edit_media_link([ $href ]) Returns a value of href attribute in atom:link element with a link relation of edit-media. If $href is given, an atom:link element with a link relation of edit-media is added. $atom->related_link([ $href ]) Returns a value of href attribute in atom:link element with a link relation of related. If $href is given, an atom:link element with a link relation of related is added. $atom->enclosure_link([ $href ]) Returns a value of href attribute in atom:link element with a link relation of enclosure. If $href is given, an atom:link element with a link relation of enclosure is added. $atom->via_link([ $href ]) Returns a value of href attribute in atom:link element with a link relation of via. If $href is given, an atom:link element with a link relation of via is added. $atom->first_link([ $href ]) Returns a value of href attribute in atom:link element with a link relation of first. If $href is given, an atom:link element with a link relation of first is added. $atom->previous_link([ $href ]) Returns a value of href attribute in atom:link element with a link relation of previous. If $href is given, an atom:link element with a link relation of previous is added. $atom->next_link([ $href ]) Returns a value of href attribute in atom:link element with a link relation of next. If $href is given, an atom:link element with a link relation of next is added. $atom->last_link([ $href ]) Returns a value of href attribute in atom:link element with a link relation of last. If $href is given, an atom:link element with a link relation of last is added. SEE ALSO
XML::Atom XML::Atom::Service AUTHOR
Takeru INOUE, <takeru.inoue _ gmail.com> LICENCE AND COPYRIGHT
Copyright (c) 2007, Takeru INOUE "<takeru.inoue _ gmail.com>". All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic. DISCLAIMER OF WARRANTY
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. perl v5.14.2 2012-04-04 XML::Atom::Atompub(3pm)
All times are GMT -4. The time now is 06:15 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy