2010-10-27 104 views
0

我正在为我们的集成服务器编写一个插件,它使用libxml2的xmllint命令行工具来验证XML文件。根据manual,xmllint具有禁止警告的--nowarning选项。是什么导致xmllint警告?

现在,我的问题很简单,我可能只是错过了明显的东西,但是是什么原因导致了这样的警告?如果我不知道它是什么样子的话,这很难分析输出:-)

回答

2

如果解析或验证文档时出现问题,可能会发出警告。

举个简单的例子,其中一个警告,因为无效的XML版本发出:

<?xml version="dummy"?> 
<note> 
    <to>Tove</to> 
    <from>Jani</from> 
    <heading>Reminder</heading> 
    <body>Don't forget me this weekend!</body> 
</note> 

运行:

$ xmllint test.xml 
test.xml:1: warning: Unsupported version 'dummy' 
<?xml version="dummy"?> 
        ^
<?xml version="dummy"?> 
<note> 
    <to>Tove</to> 
    <from>Jani</from> 
    <heading>Reminder</heading> 
    <body>Don't forget me this weekend!</body> 
</note> 

,如果你也有--htmlout--nowarning选项仅选项集。

$ xmllint --nowarning --htmlout test.xml 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" 
     "http://www.w3.org/TR/REC-html40/loose.dtd"> 
<html><head><title>xmllint output</title></head> 
<body bgcolor="#ffffff"><h1 align="center">xmllint output</h1> 
<?xml version="dummy"?> 
<note> 
    <to>Tove</to> 
    <from>Jani</from> 
    <heading>Reminder</heading> 
    <body>Don't forget me this weekend!</body> 
</note> 
</body></html> 

xmllint的源代码是here

+0

优秀,谢谢 – n3rd 2010-10-27 10:09:23