Shell script to map XML nodes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to map XML nodes
# 1  
Old 03-25-2008
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>
<node><nodename>subnode2</nodename></node>
</node>
</node>

and i want my output to be something along the lines of

.
./topnode
./topnode/subnode1
./topnode/subnode2

The XML files I am working with are 5-15 thousand lines long, and have many layers as above. I am able to get the nodes and so forth using SED and GREP without issue, but mapping them is a whole other challenge.

Any one any ideas?

thanks in advance,
mark
# 2  
Old 03-25-2008
Traditional Unix tools are not particularly good at this. If the file is monotonously structured you can get lucky but you're probably better off in the long run if you learn some basic XSLT or similar. This should be quite natural in that formalism (for perverse values of "natural"; it's a horrible formalism, as such).
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

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... (4 Replies)
Discussion started by: Ophiuchus
4 Replies

2. Shell Programming and Scripting

Shell script to get one to one map and rename the filename

I have 2 files sorted by numerically. I need help with shell script to read these 2 files and do a 1:1 mapping and rename the filenames with the mapped case#; For example: cat case.txt 10_80 10_90 cat files.txt A BCD_x 1.pdf A BCD_x 2.pdf ls pdf_dir A BCD_x 1.pdf A BCD_x 2.pdf ... (2 Replies)
Discussion started by: iaav
2 Replies

3. Shell Programming and Scripting

Parsing XML using shell script

Well, issue is i have to parse this script to get the VERSION: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>CFBundleAllowMixedLocalizations</key> ... (9 Replies)
Discussion started by: zorosinister
9 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

Array or map Concept in Shell Script

Need a urgent help I have a data like below 044 CN CNP 032 MB MBD 567 NH NHI 678 GY GYP . . . . 250 records above data are loaded from a table ... I have a shell script which will read each line and in a specific position it has extn code like ... 044 or 032 ... i need... (3 Replies)
Discussion started by: greenworld123
3 Replies

6. Shell Programming and Scripting

XML parsing using shell script

I have a xml file like this <bul:collectionStrategy name="strategy1"> <bul:collectionTemplateGroup name="15min group"/> <bul:collectionTemplateGroup name="hourly group"/> </bul:collectionStrategy> <bul:CollectionTemplateGroup name="hourly group" > ... (2 Replies)
Discussion started by: LavanyaP
2 Replies

7. Shell Programming and Scripting

XML parsing in a shell script.

Below is a XML I have... <?xml version="1.0" encoding="UTF-8" ?> <component xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:XXXXX-www-Install-Manifest manifest.xsd" xmlns="urn:qqqqq-Install-Manifest" name="OM" ... (1 Reply)
Discussion started by: dashok.83
1 Replies

8. Shell Programming and Scripting

Parsing XML using Shell Script

Hello, I'm a starting shell scripter and no Perl knowledge. I've trying to do this for a while: I want to parse an XML file and get certain data out of it and write that data into a CSV file, all this using Shell Scripting (in Bash). Or Perl without any XML Parser/Interpreter (if possible). ... (1 Reply)
Discussion started by: Kage Musha
1 Replies

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

10. UNIX for Dummies Questions & Answers

generate xml from a shell script

Hello! I would like to generate an xml file from the output of various commands generated from within a shell script (some will be in CDATA). At the moment the only solution I have come up with is echoing xml tags around the commands eg. echo "<bitism>" >> outputfile /usr/sbin/prtconf... (1 Reply)
Discussion started by: speedieB
1 Replies
Login or Register to Ask a Question