The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
More efficent Data Parsing Starcast Shell Programming and Scripting 3 10-22-2009 05:45 PM
Question about Awk for Data Parsing EconResearch Shell Programming and Scripting 5 03-26-2009 08:04 PM
Parsing the data Archana.Dheepan Shell Programming and Scripting 1 01-06-2009 10:19 AM
how to verify that copied data to remote system is identical with local data. ynilesh Shell Programming and Scripting 3 01-31-2008 08:55 AM
Parsing XML dynamic data via awk? corwin43 UNIX for Dummies Questions & Answers 5 11-02-2001 12:40 PM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #2 (permalink)  
Old 4 Weeks Ago
frans's Avatar
frans frans is offline
Registered User
  
 

Join Date: Oct 2009
Location: Drôme, France
Posts: 131
Here a little script i commited yesterday for personal use.

Code:
XmlRead ()	{	# [1:(-v:verbose)]	2:branch to explore 3:Tag de fin
	ReadTag ()	{
		read L || return 1
		T=$(echo ${L%%>*>} | sed -e 's/[<>]//g' -e 's/:/_/g')
	}
	[ -n "$3" ] && OPT="$1" && shift
	local T=""
	local V=""
	while ReadTag
	do
		[[ $T = $2 ]] && break
		[[ $T != $1 ]] && continue
		[ "$OPT" = "-v" ] && echo "Tag: $T"
		while ReadTag
		do
			[[ $T = "/$1" ]] && break
			V=$(echo $L | sed s/"<[^>]*>"/""/g)
			if [[ -n "$V" ]]
			then	eval "$T=\"$V\""
				[ "$OPT" = "-v" ] && echo "$T=$V"
			else [ "$OPT" = "-v" ] && echo "Tag: $T"
			fi
		done
		[ "$OPT" = "-v" ] && echos 50 "-"
		return 0
	done
	return 1
	}

The script is called with following parameters :
1: -v to verbose, for testing and debugging purposes, outputs the variable names and values
2:subtree to explore i.e "data" will parse everithing in the subtree beginning with <data> and ending with </data>
3:endtag : permits to exit before the end of parsed file
the function returns false if EOF or endtag is reached.
possible usage

Code:
while ReadXml -v "data" "endofdata"
do
     something
     ...
done < $XmlFile

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:16 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0