[libvirt] PATCH: Add a tool virt-xml-validate
Daniel Veillard
veillard at redhat.com
Thu Apr 16 15:29:52 UTC 2009
On Thu, Apr 16, 2009 at 01:57:06PM +0100, Daniel P. Berrange wrote:
> 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 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/
>
> 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.
Right, I tend to think of virsh a bit too much as the generic toolbox
maybe it should not end up like xmllint ;-)
> > 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
It's true that we don't preserve and save back comments so ...
> > 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.
It's just a tad bit nicer IMHO,
ACK
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