$ xmlstarlet val --help
XMLStarlet Toolkit: Validate XML document(s)
Usage: xmlstarlet val <options> [ <xml-file-or-uri> ... ]
where <options>
-w or --well-formed - validate well-formedness only (default)
-d or --dtd <dtd-file> - validate against DTD
-s or --xsd <xsd-file> - validate against XSD schema
-E or --embed - validate using embedded DTD
-r or --relaxng <rng-file> - validate against Relax-NG schema
-e or --err - print verbose error messages on stderr
-b or --list-bad - list only files which do not validate
-g or --list-good - list only files which validate
-q or --quiet - do not list files (return result code only)
NOTE: XML Schemas are not fully supported yet due to its incomplete
support in libxml2 (see http://xmlsoft.org)
XMLStarlet is a command line toolkit to query/edit/check/transform
XML documents (for more information see http://xmlstar.sourceforge.net/)
在你的情况下,用法应该是这样的:
xmlstarlet val --xsd your_schema.xsd your_file.xml
# 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我使用:
.dll /type:CFGCLASS &重命名schema0。xsd CFGCLASS.xsd < / p >
获得xsd的名称,我使用:
xmlstarlet sel - t - m / XXX / * - v本地名称()$ 1 | sed ' s / $ / / < / p >