[libvirt] PATCH: Add a tool virt-xml-validate

Daniel Veillard veillard at redhat.com
Thu Apr 16 12:42:08 UTC 2009


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 at 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/

> 
> I've included a man page in the command. 
> 
> This patch also fixes numerous bugs in the virsh man page source

  great :)

> 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/

[...]
> +++ 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 ...

  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 :-)

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel at veillard.com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/




More information about the libvir-list mailing list