Visit Our UNIX and Linux User Community


Generate a XML file from a text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Generate a XML file from a text file
# 1  
Old 10-06-2009
Generate a XML file from a text file

FILE-1
Code:
USER  	username@foo.com
TOOLIN  	tool-a
TOOL2	tool-b
TOOL3	tool-c
TOOL4	tool-d
TOOL5	tool-e
USER	username_2@foo.com
TOOLIN  	tool-e
TOOL2	tool-f
TOOL3	tool-c
TOOL4	tool-d
 ....

I need to take this file and generate a target XML file -
Code:
 <access>
      <managed>
      <!-- Admin Servlet names listed here have access controls enforced -->
         <tool>tool-a</tool>
         <tool>tool-b</tool>
         <tool>tool-c</tool>
         <tool>tool-d</tool>
         <tool>tool-e</tool>
         <tool>tool-f</tool>
      </managed>
      <users>
         <user name="username@foo.com">
            <tools>
             <tool>tool-a</tool>
             <tool>tool-b</tool> 
             <tool>tool-c</tool>
             <tool>tool-d</tool>
             <tool>tool-e</tool>
            </tools>
         </user>
         <user name="username_2@foo.com">
           <tools>
             <tool>tool-e</tool>
             <tool>tool-f</tool> 
             <tool>tool-c</tool>
             <tool>tool-d</tool>
           </tools>
         </user>
 </users>
 </access>

Since I am new to scripting please suggest a script which can do that...

Thanks,
Jack

Last edited by pludi; 10-07-2009 at 03:12 AM.. Reason: code tags, please
# 2  
Old 10-07-2009
Please use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)

Thank You.

The UNIX and Linux Forums
# 3  
Old 10-07-2009
You can use some perl modules to do that, such as XML::Quick - search.cpan.org or some other XML related modules.
# 4  
Old 10-07-2009
Have a look at XI (XML Import)

Previous Thread | Next Thread
Test Your Knowledge in Computers #880
Difficulty: Medium
SCADA systems that tie together decentralized facilities such as power, oil, gas pipelines, water distribution and wastewater collection systems were designed to be open, robust, easily operated and repaired, and highly secure.
True or False?

10 More Discussions You Might Find Interesting

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

2. UNIX for Dummies Questions & Answers

Reading Xml file and print the values into the text file in columnwise?

hi guys, i want help... Reding XML file and print the values into the text file using linux shell script file as per below xml file <sequence> <Filename>aldorzum.doc</Filename> <DivisionCode>US</DivisionCode> <ContentType>Template</ContentType> <ProductCode>VIMZIM</ProductCode> </sequence>... (4 Replies)
Discussion started by: sravanreddy
4 Replies

3. Shell Programming and Scripting

Generate .csv file a text file

Hi guys, I have a text file that states: cat prod.hosts 11.29.130.14 host1 host1.test.com web17 11.29.130.15 host2 host2.test.com web18 11.29.130.16 host3 host3.test.com web19 I want a .csv file that states: ... (2 Replies)
Discussion started by: Junaid Subhani
2 Replies

4. Programming

How to write a java program that will parse through an XML file and generate a report?

I'm pretty new to Java and I am trying to write a program that will pick up a file from a windows directory adn parse through the XML file to produce a report that will show a total item count and a total paid amount. Any one have any suggestions? Trying to figure out where to start... (4 Replies)
Discussion started by: risarose87
4 Replies

5. Shell Programming and Scripting

Filter a .kml file (xml) with data set from text file

I have a .kml file. So I want filter the .kml to get only the tags that have this numeric codes that they are in a text file 11951 11952 74014 11964 11965 11969 11970 11971 11972 60149 74018 74023 86378 11976 11980 11983 11984 11987 (5 Replies)
Discussion started by: pcoj33
5 Replies

6. Shell Programming and Scripting

KSH - help needed for creating a script to generate xml file from text file

Dear Members, I have a table in Oracle DB and one of its column name is INFO which has data in text format which we need to fetch in a script and create an xml file of a new table from the input. The contents of a single cell of INFO column is like: Area:app - aam Clean Up Criteria:... (0 Replies)
Discussion started by: Yoodit
0 Replies

7. Programming

Generate XML file from C++

Hi, I need to generate an XML file as output for a C++ program. Immediate idea that came across to me was through fprintf by mentioning all the attribute names/fields in the XML file one by one and inserting the values there which I get from C++ program. Is there any other better way to... (2 Replies)
Discussion started by: debu
2 Replies

8. UNIX for Dummies Questions & Answers

Script to generate text file from excel file

Hello, I have a excel file which has almost ten columns on the shared drive. I have to write a shell script to ftp that daily to unix server and then extract some columns from there and generate oracle standard text file. The columns should be in proper order and aligned properly, otherwise... (1 Reply)
Discussion started by: isingh786
1 Replies

9. Shell Programming and Scripting

generate new string from a text file

Hi, I have a file and the content looks like this: line1 line2 File #5 : found '/u01/testing.txt' line5 line6 line7 File #12 : found '/u01/testabc.txt' line10 line11 I want to write a bash script to give me the output: The file 5 is '/u01/testing.txt' The file 12 is... (6 Replies)
Discussion started by: walterwaston
6 Replies

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

Featured Tech Videos