As @slhck said, the shell isn't really the right tool for writing XML (although it's not as bad as trying to parse XML in the shell...), but it's not too hard to do a quick&dirty script:
targetdir="/path/to/dir/of/files"
prefix="testfile"
outfile="$targetdir/out.xml"
# Write the opening tag(s):
echo "<path>" >"$outfile"
# Loop through the matching files, writing entries for each one:
for f in "$targetdir/$prefix"*; do
cat <<END_INSERT >>"$outfile"
<dir>
<file>$(basename "$f")</file>
</dir>
END_INSERT
done
# Write the closing tag(s):
echo "</path>" >>"$outfile"
So what's wrong with the above, that you'd want to use something with a real XML library instead? Well, consider what'd happen with the above if any filenames happen to contain "<" or ">" (which are perfectly legal characters in unix filenames)? Doing this right involves encoding the filenames with HTML entities, and (AFAIK) the shell doesn't have good tools for this; a good XML library will just handle this sort of thing for you automatically.
A couple of notes on the script: first, note that the first echo redirects with ">", while all the subsequent writes to outfile use ">>" -- that's because ">" empties the file before writing, so you want this only on the first write.
Second, I use echo for the first and last writes, but cat with a here-document in the loop -- this is just a matter of convenience, because echo is easiest for single-line writes, but here-docs are easier to do multi-line writes in. You could easily use echo everywhere, or cat << everywhere if you wanted to be consistent.
Third, I tend to double-quote everything that contains a variable. This is a way of avoiding trouble with special characters (like spaces) in things like filenames. In general, I follow the principle that you should quote everything unless there's a specific reason not to. It's bad enough the XML will have trouble with special characters, I don't want trouble at the shell level as well.