Parse XML file in shell script

Hi Everybody,

I have an XML file containing some data and i want to extract it, but the specific issue in my file is that the data is repeated some times like the following example :

<section1>
<subsection1>
X=...
Y=...
Z=...
<\subsection1>
<subsection2>
X=...
Y=...
Z=...
<\subsection2>
<\section1>

the idea is to select (or extract) X and Z for a specific subsection only, note here that the number of subsection is changing frequently, (grep didn't work).

Many thanks in advance for your help.

something like this :

SECT="subsection1"
sed -n "/<$SECT>/,/<\\\\$SECT>/ p" data.xml | sed '1d;$d' >temp
while read L
do
    eval "$L"
done < temp
echo "X='$X' - Y='$Y' - Z='$Z'"

I'd like to find a way without temp file, but piping to ta "while read" loop creates a subshell so the variables aren't availaible out of the loop.
I saw something about that in a previous post but don't remember the title...

I would say use the right tool for the right job.
Parsing XML in script won't scale, error prone.