用sheel xmllint --xpath模块进行xml解析

 

# 遍历整个代码仓下的"customization.xml" 和"customization_common.xml"文件,并执行以下操作
# 1.场景
grep -q " config_git_path" $1
if [ $? == 0 ]; 
then
    name=`xmllint --xpath "//build_desc/@config_git_path" $1 | awk -F '"' '{print $2}'| cut -d '/' -f 4-`
    path=$name
    upstream=`xmllint --xpath "//build_desc/@config_git_branch" $1 | awk -F '"' '{print $2}'`
    revision=`xmllint --xpath "//build_desc/@config_git_tag" $1 | awk -F '"' '{print $2}'`
    echo "" >> temp.xml
    echo ""
fi

# 6.xxxxxxxxxxxxx场景
grep -q "" $1
if [ $? == 0 ]; 
then
    echo $1
    name=`xmllint --xpath "//custres/git_repository/text()" $1 | cut -d '/' -f 4-`
    path=$name
    upstream=`xmllint --xpath "//custres/git_branch/text()" $1 `
    revision=`xmllint --xpath "//custres/git_repository/../@tag" $1 | awk -F '"' '{print $2}'`
    echo "" >> temp.xml
    echo ""
fi

你可能感兴趣的:(shell)