Sponsored Content
Top Forums Shell Programming and Scripting Help using SED to comment XML elements Post 302322289 by J-Hon on Wednesday 3rd of June 2009 09:11:16 AM
Old 06-03-2009
My apologies if my original example wasn't very clear. Here's some sample data pulled from the XML files:

Code:
<analysisMessages.js>
        <Source_Eng_Old />
        <Source_Eng_New>Time Graph Base Properties - Analyze activities relative to time.</Source_Eng_New>
        <Source_Trans_Old />
        <Target_Trans_New>Time Graph Base Properties - Analyze activities relative to time.</Target_Trans_New>
        <NumOfKeys>1</NumOfKeys>
        <Translation_Type>1</Translation_Type>
        <ResourceId>timeGraph€€€common_props_title</ResourceId>
</analysisMessages.js>
<ganttChartMessages.js>
        <Source_Eng_Old />
        <Source_Eng_New>Show</Source_Eng_New>
        <Source_Trans_Old />
        <Target_Trans_New>Show</Target_Trans_New>
        <NumOfKeys>1</NumOfKeys>
        <Translation_Type>1</Translation_Type>
        <ResourceId>drawGanttChartButtonCaption</ResourceId>
</ganttChartMessages.js>
<peMessages.js>
        <Source_Eng_Old />
        <Source_Eng_New>Rerun the selected job</Source_Eng_New>
        <Source_Trans_Old />
        <Target_Trans_New>Rerun the selected job</Target_Trans_New>
        <NumOfKeys>1</NumOfKeys>
        <Translation_Type>9</Translation_Type>
        <ResourceId>jobGrid€€€tooltip€€€RERUN</ResourceId>
</peMessages.js>


I'm looking specifically at the <Translation_Type> attribute, and deciding whether to comment the entire element or not based upon what that integer is.

In the sample above, I'd want the last element to be commented out in this format:

Code:
<!--<peMessages.js>
        <Source_Eng_Old />
        <Source_Eng_New>Rerun the selected job</Source_Eng_New>
        <Source_Trans_Old />
        <Target_Trans_New>Rerun the selected job</Target_Trans_New>
        <NumOfKeys>1</NumOfKeys>
        <Translation_Type>9</Translation_Type>
        <ResourceId>jobGrid€€€tooltip€€€RERUN</ResourceId>
 </peMessages.js>-->

I'm familiar with PHP, but I've only done a little XML parsing with it before. I was under the impression that while I could parse through the XML and easily match/do logic on the Translation_Type values, I wouldn't be able to drop in those comments before and after the element? I'll certainly go back and look through my notes, but I was remembering using a multi-dimensional array type data structure to access the various elements, not actually editing the raw line-by-line file itself (that part being hidden via the PHP class, obviously you can add/drop/change the XML attributes).

Last edited by J-Hon; 06-03-2009 at 10:17 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read elements of a xml file??????

Hi, What is a good way to read elements of an xml file? i did try xmllint it doesnt provide a function to output values of a tree. In the below example when i specify from Family2 I need the name of the father then the output should be DAVE. Appreciate any help provided in this regards. Many... (6 Replies)
Discussion started by: ahmedwaseem2000
6 Replies

2. Shell Programming and Scripting

get rid of xml comment by grep or sed

Hi, I would like to get rid of all comment in an xml file by grep or sed command: The content seem like this: <!-- ab cd ef gh ij kl --> Anyone can help? Thanks and Regards (3 Replies)
Discussion started by: RonLii
3 Replies

3. Shell Programming and Scripting

Using sed to comment out line in /etc/vfstab

I am running a script remotely to do the following 1. Kill all processes by a user 2. Uninstall certain packages 3. FTP over a new file 4. Kill a ldap process that is not allowing my /devdsk/c0t0d0s7 slice to un-mount 5. Unmount /h 6. comment out the slice in vfstab 7. newfs the... (9 Replies)
Discussion started by: deaconf19
9 Replies

4. Shell Programming and Scripting

Comment a line with SED

I have around 25 hosts and each hosts has 4 instance of jboss and 4 different ip attached to it . I need to make some changes to the startup scripts. Any tips appreciated. I have total of 100 instances which bind to 100 different ip address based on instance name. For example File1 ... (1 Reply)
Discussion started by: gubbu
1 Replies

5. Shell Programming and Scripting

Script to put block comment after finding regex in xml file

hi, i need my bash script to find regex in xml file.. and comment 2 lines before and after the line that contains regex.. can't use # needs to be <!-- at the beginning and --> and the end of the comment. so eg.. first block <filter> <filter-name>MyRegEx</filter-name> ... (11 Replies)
Discussion started by: Poki
11 Replies

6. Shell Programming and Scripting

Parsing XML elements and store them in array

Hi Friends Im so confused with using 'for' loop in ksh. I have a xml like the following: <serviceProvider> <serviceProviderID>1</serviceProviderID> <serviceProviderName>Balesh</serviceProviderName> <serviceFeeAmount>30.00</serviceFeeAmount> </serviceProvider>... (2 Replies)
Discussion started by: balesh
2 Replies

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

8. Shell Programming and Scripting

Extract only required elements from XML.

Hi , I have an XML like this. <Request> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <version>v44</version><messageId>7247308192</messageId><timeToLive>72000000000</timeToLive> </Request>. I want to extract on version and messageId. As in my output... (13 Replies)
Discussion started by: chetan.c
13 Replies

9. AIX

Comment out crontab using sed command

I am trying to comment out the crontab entries using sed. I want to comment it out for a particular environment say '/mypath/scripts/'. Using the full path as pattern, it is working. but using variable it is not working. i have tried double quotes too. but no luck! $ crontab -l ... (3 Replies)
Discussion started by: SKhan
3 Replies

10. UNIX for Beginners Questions & Answers

How can we extract specific elements from XML?

Hi, I have a requirement to extract specific element value dynamically from XML message. Here is the sample message: <File> <List> <main> <dir>doc/store834/archive</dir> <count>5</count> </main> <main> <dir>doc/store834/extract</dir> <count>6</count> </main> <main> ... (3 Replies)
Discussion started by: renukeswar
3 Replies
XML::Grove::AsCanonXML(3pm)				User Contributed Perl Documentation			       XML::Grove::AsCanonXML(3pm)

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.10.1 1999-10-23 XML::Grove::AsCanonXML(3pm)
All times are GMT -4. The time now is 08:14 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy