Sponsored Content
Top Forums Shell Programming and Scripting Parse an XML task list to create each task.xml file Post 302256192 by MissI on Saturday 8th of November 2008 02:53:04 PM
Old 11-08-2008
Parse an XML task list to create each task.xml file

I have an task definition listing xml file that contains a list of tasks such as

Code:
<TASKLIST
    <TASK definition="Completion date" id="Taskname1" Some other 
         <CODE name="Code12" 
               <Parameter pname="Dog" input="5.6" units="feet" etc /Parameter>
               <Parameter pname="Cat" input="cute" units="NA"      /Parameter>
          /CODE>
     /TASK>
<TASK definition="Completion date" id="Taskname2" Some other 
         <CODE name="Code3" 
          /CODE>
         <CODE name="Code2" 
           /CODE>
     /TASK>
/TASKLIST>

I need to parse the task list into seperate task xml files starting from the <TASK tag to the /TASK> tag using the TASK id for the *.xml name.

I have written a grep command to capture all id names and then a sed command along with another grep command to clean up everything except the id leaving me with a list of just Task id names. My code is not eloquant, but works.

Now I am stuck. Please help. I am a novice at Unix scripting.

Last edited by bakunin; 11-08-2008 at 06:29 PM.. Reason: Please use code-tags areoun code!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to parse a XML file using PERL and XML::DOm

I need to know the way. I have got parsing down some nodes. But I was unable to get the child node perfectly. If you have code please send it. It will be very useful for me. (0 Replies)
Discussion started by: girigopal
0 Replies

2. Shell Programming and Scripting

comment and Uncomment single task out of multiple task

I have a file contains TASK gsnmpproxy { CommandLine = $SMCHOME/bin/gsnmpProxy.exe } TASK gsnmpdbgui { CommandLine = $SMCHOME/bin/gsnmpdbgui.exe I would like to comment and than uncomment specific task eg TASK gsnmpproxy Pls suggest how to do in shell script (9 Replies)
Discussion started by: madhusmita
9 Replies

3. Shell Programming and Scripting

How can I parse xml file?

How can I parse file containing xml ? I am sure that its best to use perl - but my perl is not very good - can someone help? Example below contents of file containing the xml - I basically want to parse the file and have each field contained in a variable.. ie. I want to store the account... (14 Replies)
Discussion started by: frustrated1
14 Replies

4. Shell Programming and Scripting

parse xml file

Hello all, Given the following extract from a xml file with multiple <JOB> .... </JOB> entries <JOB APPLICATION="APP" APR="0" AUG="0" AUTHOR="AUT" AUTOARCH="0" CMDLINE="/tmp/test1 %%var" CONFIRM="1" CREATION_DATE="20100430" CREATION_TIME="130739" ... (2 Replies)
Discussion started by: cabrao
2 Replies

5. Shell Programming and Scripting

Create xml file using a content from another xml file

I need to create a xml file(master.xml) with contents from another xml files(children). I have below list of xml files in a temporary location (C:/temp/xmls) 1. child1.xml 2. child2.xml Below is the content of the child1.xml & child2.xml files, child1.xml <root> <emp> ... (3 Replies)
Discussion started by: vel4ever
3 Replies

6. UNIX for Dummies Questions & Answers

Need help how to create a file (xml) list all files from directory

I have more than 10K songs in two directories on a hard drive. I would like to create a file list all of files name then change to .xml extension to upload to iPhone so I have a Karaoke list on my iPhone. I need your help to create a file by using command in Linux. Files names: 0001 More... (4 Replies)
Discussion started by: ggcc
4 Replies

7. UNIX for Dummies Questions & Answers

Parse xml file

HI Guys, Input .XML <xn:MeContext id="L0307"> <xn:ManagedElement id="1"> <xn:VsDataContainer id="1"> <xn:attributes> <xn:vsDataType>vsDataENodeBFunction</xn:vsDataType> ... (3 Replies)
Discussion started by: pareshkp
3 Replies

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

9. Shell Programming and Scripting

Create one xml file from one list of names

Actually I have one list of channels names like: Rai 1 Rai 1 +1HD Rai 1 +2HD Rai 2 Rai 2 +1HD Rai 2 +2HD . . . .From this list of names I need create one new xml file with this structure <channel id="Rai 1"> <display-name lang="it">Rai 1</display-name> <icon... (3 Replies)
Discussion started by: Tapiocapioca
3 Replies

10. UNIX for Beginners Questions & Answers

Need list of input and output parameter of task in a text file, using shell script

//file begin ===== //some code task abcd_; input x; input y,z; //some comment output w; //some comment reg p; integer q; begin //some code end endtask : abcd_ //some code //file end ===== expected output from above... (1 Reply)
Discussion started by: rishifrnds
1 Replies
STAG-GREP(1p)						User Contributed Perl Documentation					     STAG-GREP(1p)

NAME
stag-grep - filters a stag file (xml, itext, sxpr) for nodes of interest SYNOPSIS
stag-grep person -q name=fred file1.xml stag-grep person 'sub {shift->get_name =~ /^A*/}' file1.xml stag-grep -p My::Foo -w sxpr record 'sub{..}' file2 USAGE
stag-grep [-p|parser PARSER] [-w|writer WRITER] NODE -q tag=val FILE stag-grep [-p|parser PARSER] [-w|writer WRITER] NODE SUB FILE stag-grep [-p|parser PARSER] [-w|writer WRITER] NODE -f PERLFILE FILE DESCRIPTION
parsers an input file using the specified parser (which may be a built in stag parser, such as xml) and filters the resulting stag tree according to a user-supplied subroutine, writing out only the nodes/elements that pass the test. the parser is event based, so it should be able to handle large files (although if the node you parse is large, it will take up more memory) ARGUMENTS
-p|parser FORMAT FORMAT is one of xml, sxpr or itext, or the name of a perl module xml assumed as default -w|writer FORMAT FORMAT is one of xml, sxpr or itext, or the name of a perl module -c|count prints the number of nodes that pass the test -filterfile|f a file containing a perl subroutine (in place of the SUB argument) -q|query TAG1=VAL1 -q|query TAG2=VAL2 ... -q|query TAGN=VALN filters based on the field TAG other operators can be used too - eg <, <=, etc multiple q arguments can be passed in for more complex operations, pass in your own subroutine, see below SUB a perl subroutine. this subroutine is evaluated evry time NODE is encountered - the stag object for NODE is passed into the subroutine. if the subroutine passes, the node will be passed to the writer for display NODE the name of the node/element we are filtering on FILE the file to be parser. If no parser option is supplied, this is assumed to a be a stag compatible syntax (xml, sxpr or itext); otherwise you should parse in a parser name or a parser module that throws stag events SEE ALSO
Data::Stag perl v5.10.0 2008-12-23 STAG-GREP(1p)
All times are GMT -4. The time now is 05:46 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy