Sponsored Content
Top Forums Shell Programming and Scripting XML to Text file Parsing Using shell scripting Post 302621649 by chihung on Tuesday 10th of April 2012 08:33:14 PM
Old 04-10-2012
Install perl XML::XPath module
Code:
# yum install perl-XML-XPath.noarch
or
# perl -MCPAN -e 'install XML::XPath'

Try this:
Code:
#! /usr/bin/perl
use XML::XPath;
$,=" ";

$xp=XML::XPath->new($ARGV[0]);
$nodes=$xp->find('//xn:SubNetwork');
foreach $i ($nodes->get_nodelist) {
        $sn=$i->getAttribute("id");
        foreach $j ($i->find('xn:MeContext')->get_nodelist) {
                $mc=$j->getAttribute("id");
                foreach $k ($j->find('xn:VsDataContainer/xn:attributes/es:vsDataMeContext/es:ipAddress/text()')->get_nodelist) {
                        print $sn, $mc, $k->getNodeValue(),"\n";
                }
        }
}

This User Gave Thanks to chihung For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Plz Help To convert xml file to text file using bourn shell scripts

If someone out there could help me out with this problem. I would really appreciate it. I am trying to convert xml into text file(fixed length) using Unix Borne shell scripts. My xml file: <root> <header_rec recordtype="00"> <record_id>00</record_id> <country_code>AK></country_code>... (0 Replies)
Discussion started by: ram2s2001
0 Replies

2. Solaris

XML to Text file Parsing Using shell scripting

Hi, I want to parse an XML File using Shell Script preferably by using awk command, I/P file is : <gn:ExternalGsmCell id="016P3A"> <gn:attributes> <gn:mnc>410</gn:mnc> <gn:mcc>310</gn:mcc> <gn:lac>8016</gn:lac> ... (2 Replies)
Discussion started by: tech_frk
2 Replies

3. UNIX for Dummies Questions & Answers

Delete a record in a xml file using shell scripting

find pattern, delete line with pattern and 3 lines above and 8 lines below the pattern. The pattern is "isup". The entire record with starting tag <record> and ending tag </record> containing the pattern is to be deleted and the rest to be retained. <record> ... (4 Replies)
Discussion started by: sdesstp
4 Replies

4. Shell Programming and Scripting

XML-Text Parsing Using shell scripting

HI Guys, I have to parse below xml file :- <xn:SubNetwork id="ONRM_ROOT_MO_R"> <xn:MeContext id="LP101"> <xn:ManagedElement id="1"> <xn:VsDataContainer id="1"> <xn:attributes> ... (8 Replies)
Discussion started by: asavaliya
8 Replies

5. 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

6. Shell Programming and Scripting

Scripting Language for Parsing XML

Hello, I want to know which shell scripting language (like AWk, Perl or any other) is the best for parsing and editing 1) space or Comma Separated Datsets 2) XML type Datasets. (1 Reply)
Discussion started by: ajayram
1 Replies

7. Shell Programming and Scripting

How to extract data from xml file using shell scripting?

Hi evry1, This is my 1st post in this forum.Pls help me I want to extract some data froma xml file which has 2000 lines using shell scripting. Actually my xml file has some "audio and video codes" which i need to arrange in a column wise format after extracting it using shell scripting.I... (4 Replies)
Discussion started by: arun_kohan
4 Replies

8. Shell Programming and Scripting

How to extract data from XML file using shell scripting?

Hi , I have input file as XML. following are input data #complex.xml Code: <?xml version="1.0" encoding="UTF-8"?><TEST_doc xmlns="http://www.w3.org/2001/XMLSchema-instance"> <ENTRY uid="123456"> <protein> <name>PROT001</name> <organism>Human</organism> ... (1 Reply)
Discussion started by: arun_kohan
1 Replies

9. UNIX for Dummies Questions & Answers

Shell script to read lines in a text file and filter user data Shell Programming and Scripting

sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies

10. Programming

How to write in other language in text/xml file by reading english text/xml file using C++?

Hello Team, I have 2 files.one contains english text and another contains Japanese. so i have to read english text and replace the text with Japanesh text in third file. Basically, I need a help to write japanese language in text/xml file.I heard wstring does this.Not sure how do i write... (2 Replies)
Discussion started by: SA_Palani
2 Replies
XML::Grove::AsCanonXML(3)				User Contributed Perl Documentation				 XML::Grove::AsCanonXML(3)

NAME
XML::Grove::AsCanonXML - output XML objects in canonical XML SYNOPSIS
use XML::Grove::AsCanonXML; # Using as_canon_xml method on XML::Grove objects: $string = $xml_object->as_canon_xml( OPTIONS ); # Using an XML::Grove::AsCanonXML instance: $writer = XML::Grove::AsCanonXML->new( OPTIONS ); $string = $writer->as_canon_xml($xml_object); $writer->as_canon_xml($xml_object, $file_handle); DESCRIPTION
"XML::Grove::AsCanonXML" will return a string or write a stream of canonical XML for an XML object and it's content (if any). "XML::Grove::AsCanonXML" objects hold the options used for writing the XML objects. Options can be supplied when the the object is created, $writer = XML::Grove::AsCanonXML->new( Comments => 1 ); or modified at any time before writing an XML object by setting the option directly in the `$writer' hash. OPTIONS
Comments By default comments are not written to the output. Setting comment to TRUE will include comments in the output. AUTHOR
Ken MacLeod, ken@bitsko.slc.ut.us SEE ALSO
perl(1), XML::Parser(3), XML::Grove(3). James Clark's Canonical XML definition <http://www.jclark.com/xml/canonxml.html> perl v5.16.3 1999-08-17 XML::Grove::AsCanonXML(3)
All times are GMT -4. The time now is 07:56 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy