【问题标题】:What causes an xmllint warning?是什么导致 xmllint 警告?
【发布时间】:2010-10-27 08:12:12
【问题描述】:

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

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

【问题讨论】:

    标签: xml lint


    【解决方案1】:

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

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

    【讨论】:

    • XML Lint 不再为给定示例输出警告,而是parse errors
    猜你喜欢
    • 2019-08-28
    • 2021-09-28
    • 1970-01-01
    • 2016-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-28
    相关资源
    最近更新 更多