Get xmllint to output xpath results \n-separated, for attribute selector

前端 未结 5 2015
清酒与你
清酒与你 2020-12-18 18:35

How can I get xmllint to output multiple results of xpath selector for attributes \"per line\"?

Take this example:

  

        
5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-18 19:02

    I found that Ubuntu v.14 and v.18 use too old libxml2 versions. So i solved the issue mentioned in the topic by the recompiling of libxml2 v2.9.10.

    1) Download the sources of libxml2 from http://linuxfromscratch.org/blfs/view/cvs/general/libxml2.html

    2) Download the test suite:

    $ wget http://www.w3.org/XML/Test/xmlts20130923.tar.gz
    

    3) Execute:

    $ tar xf libxml2-2.9.10.tar.gz
    

    4) Execute:

    $ cd libxml2-2.9.10/
    

    5) Execute:

    $ sed -i 's/test.test/#&/' python/tests/tstLastError.py
    

    6) Execute:

    $ export CPATH="/usr/include/python3.6/:$CPATH"
    

    7) Execute:

    $ sudo apt-get install -y python3-libxml2 python3-pip
    

    8) Execute:

    $ sudo pip3 install libxml2dom
    

    9) Execute:

    $ ./configure --prefix=/usr --disable-static --with-history --with-python=/usr/bin/python3 && make
    

    Ensure here that the returning code ($?) is 0.

    10) Execute:

    $ tar xf ../xmlts20130923.tar.gz
    

    11) Execute:

    make check > check.log
    

    Ensure here that the returning code ($?) is 0.

    12) Execute:

    $ sudo make install
    

    Enjoy

    $ xmllint data.xml -xpath "//some_child/ancestor::some_parent/attribute::id"                                                                               
     id="1"
     id="10010"
     id="10011"
     id="10020"
     id="10021"
    

提交回复
热议问题