Commenting a block of code in xml where the tags may be similar


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Commenting a block of code in xml where the tags may be similar
# 1  
Old 09-03-2013
Commenting a block of code in xml where the tags may be similar

I want to comment a block of code in xml. Note that the tags will be similar. In the below xml code, I want to block the listener block for com.pkg1.class2. How do i do it ?

Thanks in Advance

Code:
<listener>
<listener-class>com.pkg1.class1</listener-class>
</listener>
.........
<listener>
<listener-class>com.pkg1.class2</listener-class>
</listener>
............

# 2  
Old 09-03-2013
Please post detail what kind of output you want?
# 3  
Old 09-03-2013
Like this:
Code:
awk '/com.pkg1.class2/' RS="</listener>\n" ORS="</listener>\n" file
.........
<listener>
<listener-class>com.pkg1.class2</listener-class>
</listener>

?
# 4  
Old 09-04-2013
Quote:
Originally Posted by learnbash
Please post detail what kind of output you want?

I want the xml file with that block commented out or removed.

---------- Post updated at 05:21 AM ---------- Previous update was at 05:19 AM ----------

Quote:
Originally Posted by RudiC
Like this:
Code:
awk '/com.pkg1.class2/' RS="</listener>\n" ORS="</listener>\n" file
.........
<listener>
<listener-class>com.pkg1.class2</listener-class>
</listener>

?

This didn't work. What I wanted is the same xml file with the block i am searching for, commented out.
# 5  
Old 09-04-2013
Using Perl Tie::File

Code:
#!/usr/bin/perl -w

use strict;
use Tie::File;
my $i;
my @array;
my $file = "./test.xml";
tie @array, 'Tie::File', $file or die;

for($i=0;$i<$#array;$i++) {
   if($array[$i] =~ /<listener-class>com\.pkg1\.class2<\/listener-class>/) {
      $array[$i] = '<!'.$array[$i].'-->';
      $array[$i-1] = '<!'.$array[$i-1].'-->';
      $array[$i+1] = '<!'.$array[$i+1].'-->';
   }
}

untie @array;

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to pull multiple XML tags from the same XML file in Shell.?

I'm searching for the names of a TV show in the XML file I've attached at the end of this post. What I'm trying to do now is pull out/list the data from each of the <SeriesName> tags throughout the document. Currently, I'm only able to get data the first instance of that XML field using the... (9 Replies)
Discussion started by: hungryd
9 Replies

2. Shell Programming and Scripting

How to add Xml tags to an existing xml using shell or awk?

Hi , I have a below xml: <ns:Body> <ns:result> <Date Month="June" Day="Monday:/> </ns:result> </ns:Body> i have a lookup abc.txtt text file with below details Month June July August Day Monday Tuesday Wednesday I need a output xml with below tags <ns:Body> <ns:result>... (2 Replies)
Discussion started by: Nevergivup
2 Replies

3. Shell Programming and Scripting

Shell Command to compare two xml lines while ignoring xml tags

I've got two different files and want to compare them. File 1 : HTML Code: <response ticketId="944" type="getQueryResults"><status>COMPLETE</status><description>Query results fetched successfully</description><recordSet totalCount="1" type="sms_records"><record... (1 Reply)
Discussion started by: Shaishav Shah
1 Replies

4. Shell Programming and Scripting

How to add the multiple lines of xml tags before a particular xml tag in a file

Hi All, I'm stuck with adding multiple lines(irrespective of line number) to a file before a particular xml tag. Please help me. <A>testing_Location</A> <value>LA</value> <zone>US</zone> <B>Region</B> <value>Russia</value> <zone>Washington</zone> <C>Country</C>... (0 Replies)
Discussion started by: mjavalkar
0 Replies

5. UNIX for Dummies Questions & Answers

Code commenting Problems in shell scripting

Hi Friends, I Want to comment one line of code from below code. DBA_ORACLE_USER=`DB.sh -u -a User` DBA_ORACLE_PWORD=`DB.sh -p -a User` sqlplus /nolog <<-END > ${logfile} 2>&1 WHENEVER OSERROR EXIT 9 WHENEVER SQLERROR EXIT SQL.SQLCODE connect... (3 Replies)
Discussion started by: as234301
3 Replies

6. Shell Programming and Scripting

Replacing part of XML code inside comment tags

Hello! I'd like to modify custom values in a XML config file between comment tags using bash script. <feature> <keyboardshortcut>C-m</keyboardshortcut> <option1>disabled</option2> <option2>enabled</option2> </feature> <!-- bash script features START --> <feature> ... (2 Replies)
Discussion started by: prism1
2 Replies

7. UNIX and Linux Applications

Commenting out block of code in emacs in python mode

Hi, I am not sure if this is the right forum to post an emacs question, but if you could point me to an appropriate emacs forum that would be useful too. Anyway, here is the description of the problem: I usually develop python code with emacs, emacs being in python code. On my desktop a... (0 Replies)
Discussion started by: alex57326
0 Replies

8. Shell Programming and Scripting

Commenting xml file lines

Hi , I have a XML file like this <dependency> <groupId>fr.xxxx.portail.ear</groupId> <artifactId>_xxxEAR</artifactId> <version>1.0.0-20xxxxx.xxxxx-x</version> <type>ear</type> </dependency> I need to comment single/multiple lines from XML file. How can i... (6 Replies)
Discussion started by: scorpio
6 Replies

9. Shell Programming and Scripting

How to execute the rest of the code after commenting multiple lines?

Hi, As I have seen in this forum how to comment multiple lines in the script, but it does not work properly for me. It is blocking the code but it does not execute the rest of the codes. This is my code #! /usr/bin/ksh month='date +"m%"' : << Comments Block if || then echo "inc =... (12 Replies)
Discussion started by: Yamini Thoppen
12 Replies
Login or Register to Ask a Question