1

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

现在,我的问题很简单,我可能只是遗漏了一些明显的东西,但是是什么导致了这样的警告?如果我不知道它到底是什么样子,那么解析输出有点困难:-)

4

1 回答 1

3

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

这是一个简单的示例,其中由于 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>

--nowarning仅当您还设置了该选项时,该选项才有效--htmlout

$ 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 的源代码在这里

于 2010-10-27T10:06:09.830 回答