Extract text in while loop

Hi everyone,
I have managed to extract the xml data i need from a text file by using the command below. The xml data extracted has the following form:
(el3 element is optional, and el1 and el2 may have white spaces)

<Title><Doc>MyTitle</Doc>
<El1>My el1 is that</El1>
<El2>My el2 is that</El2>
<El3>My el3 is that</El3>
<Title><Doc>MyTitle 2</Doc>
<El1>My el1 is 123</El1>
<El2>My el2 is kajaer</El2>
<Title><Doc>MyTitle 3</Doc><El1>My el1 is that</El1>
<El2>My el2 is that and that</El2>
<El3>My el3 is that and this</El3>
 
more textFile | grep pattern1 | ....... | '/<El1>|<El2>|<El3>|<Title>/' | while read output;
 
do 
echo $output | grep Title > /dev/null
if [ $? -eq 0 ]; then
echo "------------------"
echo "My Title = $output "
read output
fi 
el1=$(echo $output )
read output
el2=$(echo $output )
read output
el3=$(echo $output )
 
echo "El1 = $el1 and El2 is $el2 and El3 is $el3."
 
done

There are two problems with this code. The first one is that if the elements have white space the echo outputs (reads until white space) :
<El1>My
The second problem is how should i deal with the optionality of el3.
If the line is read every time, and the element el3 is not present , the following Title element is considered as el3.

Thanks in advance

---------- Post updated at 12:22 PM ---------- Previous update was at 11:08 AM ----------

I have managed to solve the first problem, instead of read output , i read line. Now i just want to do the following , when i read a line that does not match a specific pattern , i would like to return the cursor to it's initial position , one line up. For example:

read line
echo $line | grep el3 > /dev/null
if [ $? -eq 0 ]; then
# ----- go up one line, so as to read the line again in the next iteration 
fi

I also tried using continue in the if block but it does not work properly
Please advise

Can you give us bit more information clearly

Consider the following xml document:

<Title><Doc>MyTitle</Doc>
<El1>My el1 is that</El1>
<El2>My el2 is that</El2>
<El3>My el3 is that</El3>
<Title><Doc>MyTitle 2</Doc>
<El1>My el1 is 123</El1>
<El2>My el2 is kajaer</El2>
<Title><Doc>MyTitle 3</Doc><El1>My el1 is that</El1>
<El2>My el2 is that and that</El2>
<El3>My el3 is that and this</El3>

I manage to get this xml through the following command :

more textFile | grep pattern1 | ....... | '/<El1>|<El2>|<El3>|<Title>/' | while read line;

And inside the while read line :

do 
echo $line | grep Title > /dev/null
if [ $? -eq 0 ]; then
echo "------------------"
echo "My Title = $line "
read line
fi 
el1=$(echo $line )
read line
el2=$(echo $line )
read line
echo $line | grep el1  > /dev/null
 if [ $? -eq 0 ]; then
  continue
 
 fi
el3=$(echo $line )
 
echo "El1 = $el1 and El2 is $el2 and El3 is $el3."
 
done

If the el3 is missing in the xml document as it is optional , the third read line , will read the next <Title> element, and will move the cursor one line down , which is not desirable . What i want to achieve inside this block :

 
 if [ $? -eq 0 ]; then
  continue
 
 fi

is to move the read cursor one line up , so as to re-read the <Title> element in the next loop. Also i cannot use goto.

Why are you using more?

grep pattern1 textfile | ....

Don't use grep to check a string; use case:

case $line in
     *Title*) echo "My Title = $line " ;;
esac

Why are you using command substitution instead of a direct assignment?

el1=$line