Tabulate nodes and subnodes of XML file script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Tabulate nodes and subnodes of XML file script
# 1  
Old 04-02-2014
Tabulate nodes and subnodes of XML file script

Hello to all,

I'd like to tabulate the content of the XML file below, I've been trying with AWK putting the Top node (<KIND>) as RS and so far I'm able to print the first and second field of each record, but I don't know how to continue with the following nodes that have more inner nodes.

The code I have so far is:
Code:
awk 'BEGIN{
           RS="<KIND>"; FS="<|>"
           print "|RN||JN|\nABx|CDy|MJp|CDy|MJp"}
{
print $3,$13
}' input.xml

The XMl input file is:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<TUPH>
	<KIND>
		<ABx>Event 1</ABx>
			<RN>
				<MO>
					<CDy>11</CDy>
					<CDy>5</CDy>				
				</MO>	
				<MO>
					<MJp>6</MJp>
					<MJp>7</MJp>
					<MJp>9</MJp>				
				</MO>				
			</RN>
			<JN>
				<MO>
					<CDy>8</CDy>				
				</MO>	
				<MO>
					<MJp>1</MJp>
					<MJp>3</MJp>			
				</MO>			
			</JN>		
	</KIND>
	<KIND>	
		<ABx>Event 2</ABx>
			<RN>
				<MO>
					<CDy>3</CDy>
				</MO>	
				<MO>
					<MJp>5</MJp>
				</MO>				
			</RN>
			<JN>
				<MO>
					<CDy>6</CDy>
				</MO>	
				<MO>
					<MJp>2</MJp>
				</MO>					
			</JN>
	</KIND>	
</TUPH>

The output desired is:
Code:
|RN||JN|
ABx|CDy|MJp|CDy|MJp
Event 1|11|6|8|1
|5|7||3
||9||
Event 2|3|5|6|2

Thanks in advance for any help.

Regards
# 2  
Old 04-03-2014
Provide a better sample of the input and the desired output...
# 3  
Old 04-03-2014
Hello shamrock,

Thanks for answer.

That is the input I have. What I can do is showing with colors as below.

I show the nodes I have to print, ABx, CDy, MJp. But CDy and MJp could belong to 2 different subnodes (RN, JN) because of that
in the output desired I put in column 2 RN as first header and in column 4 JN. And as second header I put CDy and MJp corresponding
to nodes RN and JN.

I'm attaching the output in HMTL format. And an image of the output showing in colors the header and subheader and cells in grey
are CDy's for RN and cells in green are MJp's for JN. Cells in orange are the ABx's.

I hope make sense.

Thanks in advance.

Code:
<?xml version="1.0" encoding="UTF-8"?>
<TUPH>
	<KIND>
		<ABx>Event 1</ABx>
			<RN>
				<MO>
					<CDy>11</CDy>
					<CDy>5</CDy>				
				</MO>	
				<MO>
					<MJp>6</MJp>
					<MJp>7</MJp>
					<MJp>9</MJp>				
				</MO>				
			</RN>
			<JN>
				<MO>
					<CDy>8</CDy>				
				</MO>	
				<MO>
					<MJp>1</MJp>
					<MJp>3</MJp>			
				</MO>			
			</JN>		
	</KIND>
	<KIND>	
		<ABx>Event 2</ABx>
			<RN>
				<MO>
					<CDy>3</CDy>
				</MO>	
				<MO>
					<MJp>5</MJp>
				</MO>				
			</RN>
			<JN>
				<MO>
					<CDy>6</CDy>
				</MO>	
				<MO>
					<MJp>2</MJp>
				</MO>					
			</JN>
	</KIND>	
</TUPH>

# 4  
Old 04-04-2014
Hello to all,

Somebody could help me with this please.

Thanks in advance
# 5  
Old 04-06-2014
Somebody could help me please
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Tabulate data in a table.

I have about a million tables stored as .txt files in a directory. The content of the files look like this: ages-eligible-for-study: genders-eligible-for-study: accepts-healthy-volunteers: CONTINUE 18-months-to-36-months both yes CONTINUE DONEOther examples, CONTINUE... (8 Replies)
Discussion started by: shoaibjameel123
8 Replies

2. UNIX for Dummies Questions & Answers

Reading XML file and print the values in the text file using Linux shell script

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>... (1 Reply)
Discussion started by: sravanreddy
1 Replies

3. Shell Programming and Scripting

Interacitve script for Healthcheckup of nodes

Hi This is my first post to this site.:D I want to develop a script with following steps: 1.Script1,2,3 placed at particular path on local server 2.ask for an IP and will directly pick up the correct script matching to the IP (IP could be defined in same script or a new script could be called).... (10 Replies)
Discussion started by: veronica
10 Replies

4. Shell Programming and Scripting

Strip xml element nodes based on conditions

Hi Gurus, I have a xml in which I have to remove unused element nodes. Here are the requirements 1. Remove StoreAddresses & Contacts complex element directly 2. Remove StoreItemCharacteristic element based on CharacteristicName="Organic" Here is the sample xml <?xml version="1.0"... (0 Replies)
Discussion started by: kumars_49
0 Replies

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

6. Shell Programming and Scripting

Run script on HACMP nodes?

Hello All, Anybody knows how can I run script on the AIX HACMP offline node, without logon a offline node? I would like to run a script on the online node and at same time or after the online node on the offline node. Any IDEA? :confused: (3 Replies)
Discussion started by: kalaso
3 Replies

7. Shell Programming and Scripting

Script for showing only selected nodes

Dear all, I am bit confused lately, I have a xmlfile here: file: book.xml <?xml version="1.0" encoding="ISO-8859-1"?> <bookstore> <book category="COOKING"> <title lang="en">Everyday Italian</title> <author>Giada De Laurentiis</author> <year>2005</year> ... (2 Replies)
Discussion started by: penyu
2 Replies

8. Shell Programming and Scripting

How to remove xml namespace from xml file using shell script?

I have an xml file: <AutoData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Table1> <Data1 10 </Data1> <Data2 20 </Data2> <Data3 40 </Data3> <Table1> </AutoData> and I have to remove the portion xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" only. I tried using sed... (10 Replies)
Discussion started by: Gary1978
10 Replies

9. Shell Programming and Scripting

Shell script to map XML nodes

Hi folks, I'm a bit of a novice at this but here goes. I want to read in nodes from an XML file, and map the path to each. eg the file is structured <node><nodename>.</nodename> <node><nodename>topnode</nodename> <node><nodename>subnode1</nodename></node> ... (1 Reply)
Discussion started by: mark14
1 Replies
Login or Register to Ask a Question