Help in Editing XML files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help in Editing XML files
# 1  
Old 02-21-2012
Java Help in Editing XML files

I need some help in editing a xml file, I have 2 xml files, One is Master.xml and other is a upgrade.xml. I want to moved all the values from upgrade.xml to Master.xml. challenge is upgrade.xml might have similar values, changed values and also new values.
So the script should find and replace or add in case its a new value. There should not be duplicate values.

upgrade.xml file
Code:
<test>
    <test1>
        <file name ="xyz">value1</file>
        <file name ="abc">value2</file>
        <file name ="kkk">value3</file>
   </test1>
        <folder name="ggg"> 
            <new>
           <file name="ppp"> value321 </file>
            </new>
        </folder>
            
</test>

Master.xml
Code:
<test>
   <test1>
        <file name ="ddd">value5</file>
        <file name ="xyz">value0</file>
        <file name ="abc">value2</file>
        <file name ="mmm">value6</file>
   </test1>
</test>

output file:
Code:
<test>
   <test1>
        <file name ="ddd">value5</file>
        <file name ="xyz">value1</file>
        <file name ="abc">value2</file>
        <file name ="kkk">value3</file>
        <file name ="mmm">value6</file>
   </test1>
        <folder name="ggg"> 
            <new>
           <file name="ppp"> value321 </file>
            </new>
        </folder>
</test>


Last edited by Scott; 02-21-2012 at 02:59 AM.. Reason: Code tags
# 2  
Old 02-21-2012
Install XML::Merge perl module
Code:
perl -MCPAN -e 'install XML::Merge'

Run this perl script. master.xml will merge the upgrade.xml
Code:
#! /usr/bin/perl

use XML::Merge;

my $merge_obj = XML::Merge->new(
        'filename' => 'master.xml',
        'conflict_resolution_method' => 'last-in_wins'
);

$merge_obj->merge('filename' => 'upgrade.xml');
$merge_obj->tidy();
$merge_obj->write();

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Splitting a single xml file into multiple xml files

Hi, I'm having a xml file with multiple xml header. so i want to split the file into multiple files. Sample.xml consists multiple headers so how can we split these multiple headers into multiple files in unix. eg : <?xml version="1.0" encoding="UTF-8"?> <ml:individual... (3 Replies)
Discussion started by: Narendra921631
3 Replies

2. Shell Programming and Scripting

Splitting xml file into several xml files using perl

Hi Everyone, I'm new here and I was checking this old post: /shell-programming-and-scripting/180669-splitting-file-into-several-smaller-files-using-perl.html (cannot paste link because of lack of points) I need to do something like this but understand very little of perl. I also check... (4 Replies)
Discussion started by: mcosta
4 Replies

3. Shell Programming and Scripting

Extract strings from XML files and create a new XML

Hello everybody, I have a double mission with some XML files, which is pretty challenging for my actual beginner UNIX knowledge. I need to extract some strings from multiple XML files and create a new XML file with the searched strings.. The original XML files contain the source code for... (12 Replies)
Discussion started by: milano.churchil
12 Replies

4. Shell Programming and Scripting

Bash script deleting my files, and editing files in subdirectories question

#!/bin/bash # name=$1 type=$2 number=1 for file in ./** do if then filenumber=00$number elif then filenumber=0$number fi tempname="$name""$filenumber"."$type" if (4 Replies)
Discussion started by: TheGreatGizmo
4 Replies

5. Shell Programming and Scripting

Compare two xml files while ignoring some xml tags

I've got two different files and want to compare them. File 1 : <response ticketId="944" type="getQueryResults"><status>COMPLETE</status><description>Query results fetched successfully</description><recordSet totalCount="1" type="sms_records"><record id="38,557"><columns><column><name>orge... (2 Replies)
Discussion started by: Shaishav Shah
2 Replies

6. UNIX for Dummies Questions & Answers

XML File editing in HP-UX

Hi All, I have attached the original file and the file that I have edited, please have a look. The files are named as follows original.xml and updated.xml The chunk of data that we don’t we need is below At the start of the file: The below data is not required <Data... (3 Replies)
Discussion started by: srikaka
3 Replies

7. Shell Programming and Scripting

editing files.

hello, i have a problem. suppose file.txt i want to add lines over those lines in a file if it starts and ends with how and "?" respectively. i want output like output file.txt thanks (4 Replies)
Discussion started by: yashwantkumar
4 Replies

8. Shell Programming and Scripting

Editing XML file

Hi All, i have an XML file like :- <RequestBillsRsp version="1.0"><BillSummaryData><AgreementNumberFull>13-WY-8425-2</AgreementNumberFull><AgreementNumberAbbr>WY84252</AgreementNumberAbbr><LineOfBusiness>F</LineOfBusiness><Line></Line> This is a continuous pattern. From this I need to... (6 Replies)
Discussion started by: Renjesh
6 Replies

9. Shell Programming and Scripting

Editing files to add some thing in all the files in a folder

Hi All, I have a folder that contains 100's of files and each file have a similar content like the following format: ((STBJa:200.0,((STBTz:200.0,(STSwe:200.0,(STDUw:200.0,(ST4Bu:200.0,STL2b:200.0):127.0):86.0):80.0):120.0, STAHr:200.0):134.0):200.0,STuNg:200.0);What I need is to do is add "#1"... (2 Replies)
Discussion started by: Lucky Ali
2 Replies

10. Shell Programming and Scripting

editing a xml file

I have a xml file which conttent as follows: <Config><Pro><config> <key>mac</key> <value>localhost</value> </config> </Pro></Config> i want to edit <value>localhost</value> as <value>local</value> can any one please help me on... (3 Replies)
Discussion started by: Aditya.Gurgaon
3 Replies
Login or Register to Ask a Question