As @Peter says, it is best to use tdom. Trying to parse xml with regexp's will lead to a world of pain. (see Why is it such a bad idea to parse XML with regex?)
That said, if you insist on doing it, then these are the changes you need to your script.
First you need to get the contents of the file into a variable. You are using the regexp on the file's name.
% set fp [open stats.xml]
file5
% set contents [read $fp]
<account>
<name>abc</name>
<number>1224.3414</number>
</account>
% close $fp
You also have an error in your pattern (the $ sign in front of number
). In addition value
will have the entire match. You will need an extra variable (v
below), to get just the first match, that is the number. So do the following:
% regexp "<number>(.*?)</number>" $contents value v
1
% puts $v
1224.3414