
だいぶ使い慣れてきたxmllintですが、HTMLがパースできたり、xmlの深い機能にも対応いていたり、macOSなどにもデフォルトで搭載されている事を考えると、より深く知っておく必要を感じます。
今回は、helpの内容を日本語化してみることにします。
これにより、少し不明だった機能も見えてくるかもしれません。
ちなみに、今の所、"--format"と"--xpath"と"--shell"ぐらいしか使っていないので、他の機能も興味津津です。
とりあえずHELP表示してみる
$ xmllint
Usage : xmllint [options] XMLfiles ...
	Parse the XML files and output the result of the parsing
	--version : display the version of the XML library used
	--debug : dump a debug tree of the in-memory document
	--shell : run a navigating shell
	--debugent : debug the entities defined in the document
	--copy : used to test the internal copy implementation
	--recover : output what was parsable on broken XML documents
	--huge : remove any internal arbitrary parser limits
	--noent : substitute entity references by their value
	--noenc : ignore any encoding specified inside the document
	--noout : don't output the result tree
	--path 'paths': provide a set of paths for resources
	--load-trace : print trace of all external entities loaded
	--nonet : refuse to fetch DTDs or entities over network
	--nocompact : do not generate compact text nodes
	--htmlout : output results as HTML
	--nowrap : do not put HTML doc wrapper
	--valid : validate the document in addition to std well-formed check
	--postvalid : do a posteriori validation, i.e after parsing
	--dtdvalid URL : do a posteriori validation against a given DTD
	--dtdvalidfpi FPI : same but name the DTD with a Public Identifier
	--timing : print some timings
	--output file or -o file: save to a given file
	--repeat : repeat 100 times, for timing or profiling
	--insert : ad-hoc test for valid insertions
	--compress : turn on gzip compression of output
	--html : use the HTML parser
	--xmlout : force to use the XML serializer when using --html
	--nodefdtd : do not default HTML doctype
	--push : use the push mode of the parser
	--pushsmall : use the push mode of the parser using tiny increments
	--memory : parse from memory
	--maxmem nbbytes : limits memory allocation to nbbytes bytes
	--nowarning : do not emit warnings from parser/validator
	--noblanks : drop (ignorable?) blanks spaces
	--nocdata : replace cdata section with text nodes
	--format : reformat/reindent the output
	--encode encoding : output in the given encoding
	--dropdtd : remove the DOCTYPE of the input docs
	--pretty STYLE : pretty-print in a particular style
	                 0 Do not pretty print
	                 1 Format the XML content, as --format
	                 2 Add whitespace inside tags, preserving content
	--c14n : save in W3C canonical format v1.0 (with comments)
	--c14n11 : save in W3C canonical format v1.1 (with comments)
	--exc-c14n : save in W3C exclusive canonical format (with comments)
	--nsclean : remove redundant namespace declarations
	--testIO : test user I/O support
	--catalogs : use SGML catalogs from $SGML_CATALOG_FILES
	             otherwise XML Catalogs starting from 
	         file:///etc/xml/catalog are activated by default
	--nocatalogs: deactivate all catalogs
	--auto : generate a small doc on the fly
	--xinclude : do XInclude processing
	--noxincludenode : same but do not generate XInclude nodes
	--nofixup-base-uris : do not fixup xml:base uris
	--loaddtd : fetch external DTD
	--dtdattr : loaddtd + populate the tree with inherited attributes 
	--stream : use the streaming interface to process very large files
	--walker : create a reader and walk though the resulting doc
	--pattern pattern_value : test the pattern support
	--chkregister : verify the node registration code
	--relaxng schema : do RelaxNG validation against the schema
	--schema schema : do validation against the WXS schema
	--schematron schema : do validation against a schematron
	--sax1: use the old SAX1 interfaces for processing
	--sax: do not build a tree but work just at the SAX level
	--oldxml10: use XML-1.0 parsing rules before the 5th edition
	--xpath expr: evaluate the XPath expression, imply --noout
Libxml project home page: http://xmlsoft.org/
To report bugs or get some help check: http://xmlsoft.org/bugs.html 
何もオプション指定しないとヘルプが出る仕組みのようです。
1行目の「Parse the XML files and output the result of the parsing」は
「XMLファイルを解析して解析結果を出力する」という事で、簡単に説明してくれています。
--version
display the version of the XML library used
使用されているXMLライブラリのバージョンを表示する
$ xmllint --version
xmllint: using libxml version 20903
   compiled with: Threads Tree Output Push Reader Patterns Writer SAXv1 FTP HTTP DTDValid HTML Legacy C14N Catalog XPath XPointer XInclude Iconv ISO8859X Unicode Regexps Automata Expr Schemas Schematron Modules Debug Zlib Lzma  
 
少しわかりずらいバージョン表記ですが、ちゃんとライブラリ名なども記されています。
--debug
dump a debug tree of the in-memory document
メモリ内ドキュメントのデバッグツリーをダンプします。
 
 
$ xmllint --debug alert.svg 
DOCUMENT
version=1.0
URL=alert.svg
standalone=true
namespace xml href=http://www.w3.org/XML/1998/namespace
  COMMENT
    content=?xml version="1.0" encoding="utf-8"?
  COMMENT
    content= Generator: Adobe Illustrator 15.1.0, SV...
  ELEMENT svg
    default namespace href=http://www.w3.org/2000/svg
    namespace xlink href=http://www.w3.org/1999/xlink
    ATTRIBUTE version
      TEXT compact
        content=1.1
    ATTRIBUTE id
      TEXT compact
        content=_x32_
    ATTRIBUTE x
      TEXT compact
        content=0px
    ATTRIBUTE y
      TEXT compact
        content=0px
    ATTRIBUTE width
      TEXT compact
        content=512px
    ATTRIBUTE height
      TEXT compact
        content=512px
    ATTRIBUTE viewBox
      TEXT compact
        content=0 0 512 512
    ATTRIBUTE style
      TEXT
        content=width: 128px; height: 128px; opacity: 1;...
    ATTRIBUTE space
      TEXT compact
        content=preserve
    TEXT compact
      content= 
    ELEMENT style
      ATTRIBUTE type
        TEXT compact
          content=text/css
      TEXT
        content=   .st0{fill:#4B4B4B;}  
    TEXT compact
      content= 
    ELEMENT g
      TEXT compact
        content=  
      ELEMENT path
        ATTRIBUTE class
          TEXT compact
            content=st0
        ATTRIBUTE d
          TEXT
            content=M452.938,19.112c-3.219-2.109-7.281-2.469...
      TEXT compact
        content=  
      ELEMENT path
        ATTRIBUTE class
          TEXT compact
            content=st0
        ATTRIBUTE d
          TEXT
            content=M167.063,127.034H45.844c-25.313,0-45.828...
      TEXT compact
        content=  
      ELEMENT path
        ATTRIBUTE class
          TEXT compact
            content=st0
        ATTRIBUTE d
          TEXT
            content=M475.625,186.44v86.25c15.625,0,36.375-19...
      TEXT compact
        content=  
      ELEMENT path
        ATTRIBUTE class
          TEXT compact
            content=st0
        ATTRIBUTE d
          TEXT
            content=M147.969,342.753H66.031L99.656,478.44c1....
      TEXT compact
        content= 
    TEXT compact
      content=  
svgファイルを--debugで表示してみましたが、namespaceも表示されて簡易確認できるモードのようです。
--shell
run a navigating shell
ナビゲートシェルを実行する
言わずとしれたオプションなので、詳細説明は省きます。
--debugent
debug the entities defined in the document
文書で定義されているエンティティをデバッグする
xmllint --debugent alert.svg 
new input from file: alert.svg
<?xml version="1.0"?>
<!--?xml version="1.0" encoding="utf-8"?-->
<!-- Generator: Adobe Illustrator 15.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="_x32_" x="0px" y="0px" width="512px" height="512px" viewBox="0 0 512 512" style="width: 128px; height: 128px; opacity: 1;" xml:space="preserve">
<style type="text/css">
	.st0{fill:#4B4B4B;}
</style>
<g>
	<path class="st0" d="M452.938,19.112c-3.219-2.109-7.281-2.469-10.813-0.953L188.641,127.034l-0.016,194.282l253.5,108.891   c3.531,1.516,7.594,1.156,10.813-0.969s5.156-5.703,5.156-9.563V28.69C458.094,24.831,456.188,21.221,452.938,19.112z"/>
	<path class="st0" d="M167.063,127.034H45.844c-25.313,0-45.828,20.516-45.828,45.828L0,275.472   c0,25.328,20.531,45.844,45.844,45.844h121.219V127.034z"/>
	<path class="st0" d="M475.625,186.44v86.25c15.625,0,36.375-19.313,36.375-43.11C512,205.752,491.25,186.44,475.625,186.44z"/>
	<path class="st0" d="M147.969,342.753H66.031L99.656,478.44c1.844,9.5,10.156,16.328,19.813,16.328h46.578   c6.359,0,12.359-3,16.172-8.125c3.828-5.094,5-11.703,3.188-17.813L147.969,342.753z"/>
</g>
</svg>
DOCUMENT
No entities in internal subset
No entities in external subset 
よく理解できませんが、情報表示の他に何かファイルをコントロールするんでしょうか?
あまり使わなそうな機能なので、深掘りしないでおきましょう。
--copy
used to test the internal copy implementation
内部コピーの実装をテストするために使用されます
$ xmllint --copy alert.svg 
<?xml version="1.0"?>
<!--?xml version="1.0" encoding="utf-8"?-->
<!-- Generator: Adobe Illustrator 15.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="_x32_" x="0px" y="0px" width="512px" height="512px" viewBox="0 0 512 512" style="width: 128px; height: 128px; opacity: 1;" xml:space="preserve">
<style type="text/css">
	.st0{fill:#4B4B4B;}
</style>
<g>
	<path class="st0" d="M452.938,19.112c-3.219-2.109-7.281-2.469-10.813-0.953L188.641,127.034l-0.016,194.282l253.5,108.891   c3.531,1.516,7.594,1.156,10.813-0.969s5.156-5.703,5.156-9.563V28.69C458.094,24.831,456.188,21.221,452.938,19.112z"/>
	<path class="st0" d="M167.063,127.034H45.844c-25.313,0-45.828,20.516-45.828,45.828L0,275.472   c0,25.328,20.531,45.844,45.844,45.844h121.219V127.034z"/>
	<path class="st0" d="M475.625,186.44v86.25c15.625,0,36.375-19.313,36.375-43.11C512,205.752,491.25,186.44,475.625,186.44z"/>
	<path class="st0" d="M147.969,342.753H66.031L99.656,478.44c1.844,9.5,10.156,16.328,19.813,16.328h46.578   c6.359,0,12.359-3,16.172-8.125c3.828-5.094,5-11.703,3.188-17.813L147.969,342.753z"/>
</g>
</svg> 
このオプションも内容をダンプするだけの機能のようです。
--recover
output what was parsable on broken XML documents
壊れたXML文書に対して解析可能だったものを出力する
$ xmllint --recover alert_error.svg 
alert_error.svg:12: parser error : Opening and ending tag mismatch: path line 11 and __path
-5.703,5.156-9.563V28.69C458.094,24.831,456.188,21.221,452.938,19.112z"></__path
                                                                               ^
<?xml version="1.0"?>
<!--?xml version="1.0" encoding="utf-8"?-->
<!-- Generator: Adobe Illustrator 15.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="_x32_" x="0px" y="0px" width="512px" height="512px" viewBox="0 0 512 512" style="width: 128px; height: 128px; opacity: 1;" xml:space="preserve">
<style type="text/css">
	.st0{fill:#4B4B4B;}
</style>
<g>
	<path class="st0" d="M452.938,19.112c-3.219-2.109-7.281-2.469-10.813-0.953L188.641,127.034l-0.016,194.282l253.5,108.891   c3.531,1.516,7.594,1.156,10.813-0.969s5.156-5.703,5.156-9.563V28.69C458.094,24.831,456.188,21.221,452.938,19.112z"/>
	<path class="st0" d="M167.063,127.034H45.844c-25.313,0-45.828,20.516-45.828,45.828L0,275.472   c0,25.328,20.531,45.844,45.844,45.844h121.219V127.034z"/>
	<path class="st0" d="M475.625,186.44v86.25c15.625,0,36.375-19.313,36.375-43.11C512,205.752,491.25,186.44,475.625,186.44z"/>
	<path class="st0" d="M147.969,342.753H66.031L99.656,478.44c1.844,9.5,10.156,16.328,19.813,16.328h46.578   c6.359,0,12.359-3,16.172-8.125c3.828-5.094,5-11.703,3.188-17.813L147.969,342.753z"/>
</g>
</svg> 
少し分かりづらいですが、pathタグの閉じを__pathタグに名称変更して不具合を作ってみました。
その箇所を見つけてくれるので、xml構築したときの構文チェックに使えそうです。
--huge
remove any internal arbitrary parser limits
任意の内部パーサ制限を削除
$ xmllint --huge alert.svg 
<?xml version="1.0"?>
<!--?xml version="1.0" encoding="utf-8"?-->
<!-- Generator: Adobe Illustrator 15.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="_x32_" x="0px" y="0px" width="512px" height="512px" viewBox="0 0 512 512" style="width: 128px; height: 128px; opacity: 1;" xml:space="preserve">
<style type="text/css">
	.st0{fill:#4B4B4B;}
</style>
<g>
	<path class="st0" d="M452.938,19.112c-3.219-2.109-7.281-2.469-10.813-0.953L188.641,127.034l-0.016,194.282l253.5,108.891   c3.531,1.516,7.594,1.156,10.813-0.969s5.156-5.703,5.156-9.563V28.69C458.094,24.831,456.188,21.221,452.938,19.112z"/>
	<path class="st0" d="M167.063,127.034H45.844c-25.313,0-45.828,20.516-45.828,45.828L0,275.472   c0,25.328,20.531,45.844,45.844,45.844h121.219V127.034z"/>
	<path class="st0" d="M475.625,186.44v86.25c15.625,0,36.375-19.313,36.375-43.11C512,205.752,491.25,186.44,475.625,186.44z"/>
	<path class="st0" d="M147.969,342.753H66.031L99.656,478.44c1.844,9.5,10.156,16.328,19.813,16.328h46.578   c6.359,0,12.359-3,16.172-8.125c3.828-5.094,5-11.703,3.188-17.813L147.969,342.753z"/>
</g>
</svg> 
このサンプルだけでは、何の制限が削除されているのかわかりませんね。
この機能も、あまり使わなそうな機能なのかも・・・
--noent
substitute entity references by their value
その値で実体参照を置換する
$ xmllint --noent alert.svg 
<?xml version="1.0"?>
<!--?xml version="1.0" encoding="utf-8"?-->
<!-- Generator: Adobe Illustrator 15.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="_x32_" x="0px" y="0px" width="512px" height="512px" viewBox="0 0 512 512" style="width: 128px; height: 128px; opacity: 1;" xml:space="preserve">
<style type="text/css">
	.st0{fill:#4B4B4B;}
</style>
<g>
	<path class="st0" d="M452.938,19.112c-3.219-2.109-7.281-2.469-10.813-0.953L188.641,127.034l-0.016,194.282l253.5,108.891   c3.531,1.516,7.594,1.156,10.813-0.969s5.156-5.703,5.156-9.563V28.69C458.094,24.831,456.188,21.221,452.938,19.112z"/>
	<path class="st0" d="M167.063,127.034H45.844c-25.313,0-45.828,20.516-45.828,45.828L0,275.472   c0,25.328,20.531,45.844,45.844,45.844h121.219V127.034z"/>
	<path class="st0" d="M475.625,186.44v86.25c15.625,0,36.375-19.313,36.375-43.11C512,205.752,491.25,186.44,475.625,186.44z"/>
	<path class="st0" d="M147.969,342.753H66.031L99.656,478.44c1.844,9.5,10.156,16.328,19.813,16.328h46.578   c6.359,0,12.359-3,16.172-8.125c3.828-5.094,5-11.703,3.188-17.813L147.969,342.753z"/>
</g>
</svg> 
どうやって置換するんでしょう?
このヘルプだけでは、操作方法がわかりませんね・・・
--noenc
ignore any encoding specified inside the document
文書内で指定されているエンコードを無視します
$ xmllint --noenc alert.svg 
<?xml version="1.0"?>
<!--?xml version="1.0" encoding="utf-8"?-->
<!-- Generator: Adobe Illustrator 15.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="_x32_" x="0px" y="0px" width="512px" height="512px" viewBox="0 0 512 512" style="width: 128px; height: 128px; opacity: 1;" xml:space="preserve">
<style type="text/css">
	.st0{fill:#4B4B4B;}
</style>
<g>
	<path class="st0" d="M452.938,19.112c-3.219-2.109-7.281-2.469-10.813-0.953L188.641,127.034l-0.016,194.282l253.5,108.891   c3.531,1.516,7.594,1.156,10.813-0.969s5.156-5.703,5.156-9.563V28.69C458.094,24.831,456.188,21.221,452.938,19.112z"/>
	<path class="st0" d="M167.063,127.034H45.844c-25.313,0-45.828,20.516-45.828,45.828L0,275.472   c0,25.328,20.531,45.844,45.844,45.844h121.219V127.034z"/>
	<path class="st0" d="M475.625,186.44v86.25c15.625,0,36.375-19.313,36.375-43.11C512,205.752,491.25,186.44,475.625,186.44z"/>
	<path class="st0" d="M147.969,342.753H66.031L99.656,478.44c1.844,9.5,10.156,16.328,19.813,16.328h46.578   c6.359,0,12.359-3,16.172-8.125c3.828-5.094,5-11.703,3.188-17.813L147.969,342.753z"/>
</g>
</svg> 
エンコードなので2バイト文字などを入れていると強制的にOS使用の文字エンコードに変換されるんでしょうか?
--noout
don't output the result tree
結果ツリーを出力しません
 
xmllint --noout alert.svg  
標準出力がされません。
あまり使う機械がなさそうですね。
--path 'paths'
provide a set of paths for resources
リソースへの一連のパスを提供する
$ xmllint sample.xml --path
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<hoge>
    <hage name="aaa" value="12345" a="1">DOG</hage>
    <hage name="bbb" value="56789" b="2">CAT</hage>
</hoge> 
pathsには何を挿入すればいいのでしょう?
現時点ではさっぱりわかりません・・・
続きは明日・・・
かなり長引きそうな感じがするので、続きは次回に持ち越すことにします・・・
お楽しみに!!
 
0 件のコメント:
コメントを投稿