
On Thu, Apr 16, 2009 at 02:42:08PM +0200, Daniel Veillard wrote:
On Thu, Apr 16, 2009 at 12:53:06PM +0100, Daniel P. Berrange wrote:
While we install our RNG schemas into the filesystem, and users could use xmllint to validate them, it is a little tedious to use this way.
This patch adds a nice simple command
virt-xml-validate XML-FILE [SCHEMA-NAME]
You can use it on any XML file format that libvirt knows about
# virt-xml-validate ~/rhel5xen.xml /home/berrange/rhel5xen.xml validates #$ echo $? 0
I normally figures out the SCHEMA-NAME from the top level element name, but you can override it if desired
# virt-xml-validate ~/bug.xml virt-xml-validate: cannot determine schema type for /home/berrange/bug.xml # virt-xml-validate ~/bug.xml domain /home/berrange/bug.txt:1: parser error : Start tag expected, '<' not found From bugzilla@redhat.com Fri Feb 27 01:12:11 2009 ^
Sounds good, I'm wondering a bit why it's better to separate it rather than make it a virsh command/
Well its not part of any libvirt API, and I don't want to require a libvirt connection in order to use it. We've got alot of other virt-XXX commands so I think its nicer to keep it separate.
The 'src/' directory is getting over large, so I decided we should have a separate 'tools' directory for command line programs included in the main libvirt source. We could consider moving virsh here perhaps.
I would wait after 0.6.3 for this, i.e. the next flow of patches, but yes we should start to clean up src/
Yeah, works for me.
[...]
+++ b/tools/virt-xml-validate.in Thu Apr 16 12:44:17 2009 +0100 @@ -0,0 +1,151 @@ [...] +if [ -z "$TYPE" ]; then + ROOT=`xmllint --format $XMLFILE 2>/dev/null| head -2 | tail -1` + case $ROOT in + *domain*) + TYPE="domain"
Hum, that doesn't really work in the general case, you can have plenty of stuff on the two first lines like the xml declaration or comments, or stylesheet PI ...
I figured no one ever uses that stuff ;-P
Instead I would use the streaming debug output to get the information whithout guess from the parser itself:
xmllint --stream --debug $XMLFILE 2>/dev/null | grep "^0 1 " | awk '{ print $3 }'
the root top level element will show up as 0 1 foo ... and there should be only one per document :-)
Will change it to do that instead. Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|