私は、Microsoft の xsd を使用して、.NET ファイルから xsd を生成する傾向があります。また、xmlstarlet を使用して xml のセクションを解析します。最後に役立つ無料ツールは altovaxml で、次の URL で入手できます: http://www.altova.com/download_components.html。
これにより、すべての xml ファイルをスキャンして、xml を解析して使用する xsd を選択できます。
# Function:
# verifyschemas - Will validate all xml files in a configuration directory against the schemas in the passed in directory
# Parameters:
# The directory where the schema *.xsd files are located. Must be using dos pathing like: VerifySchemas "c:\\XMLSchemas\\"
# Requirements:
# Must be in the directory where the configuration files are located
#
verifyschemas()
{
for FILENAME in $(find . -name '*.xml' -print0 | xargs -0)
do
local SchemaFile=$1$(getconfignamefromxml $FILENAME).xsd
altovaxml /validate $FILENAME /schema $SchemaFile > ~/temp.txt 2> /dev/null
if [ $? -ne 0 ]; then
printf "Failed to verify: "
cat ~/temp.txt | tail -1 | tr -d '\r'
printf " - $FILENAME with $SchemaFile\n"
fi
done
}
私が使用する xml を生成するには: xsd DOTNET.dll /type:CFGCLASS & rename schema0.xsd CFGCLASS.xsd
私が使用する xsd 名を取得するには: xmlstarlet sel -t -m /XXX/* -v local-name() $1 | sed 's/ $//'
これにより、xml ファイル内の要素タグを使用して正しい XSD を取得できます。
最終的な結果として、bash 関数を呼び出してすべての XML ファイルをスキャンし、それらを検証できるようになりました。それらが複数のサブディレクトリにある場合でも。