This comment use only sh/bash commands and methods ! /test.xml is your XML type file at first question...
#!/bin/sh
cat /test.xml | while read line;do
[ "$(echo "$line" | grep "<host>")" ]&& echo "host: $(echo $line | cut -f3 -d'[' | cut -f1 -d']')"
[ "$(echo "$line" | grep "<username>")" ]&& echo "username: $(echo $line | cut -f3 -d'[' | cut -f1 -d']')"
[ "$(echo "$line" | grep "<password>")" ]&& echo "password: $(echo $line | cut -f3 -d'[' | cut -f1 -d']')"
[ "$(echo "$line" | grep "<dbname")" ]&& echo "dbname: $(echo $line | cut -f3 -d'[' | cut -f1 -d']')"
done
output:
host: localhost
username: root
password: pass123
dbname: testdb
if u want write this values to file use this method :
#!/bin/sh
cat /test.xml | while read line;do
[ "$(echo "$line" | grep "<host>")" ]&& echo "$line" | cut -f3 -d'[' | cut -f1 -d']'> /config/global/resources/default_setup/connection/host
[ "$(echo "$line" | grep "<username>")" ]&& echo "$line" | cut -f3 -d'[' | cut -f1 -d']'> /config/global/resources/default_setup/connection/username
[ "$(echo "$line" | grep "<password>")" ]&& echo "$line" | cut -f3 -d'[' | cut -f1 -d']'> /config/global/resources/default_setup/connection/password
[ "$(echo "$line" | grep "<dbname")" ]&& echo "$line" | cut -f3 -d'[' | cut -f1 -d']'> /config/global/resources/default_setup/connection/dbname
done
this method will overwrite your local files used only getting values (your datas will lost from output files)