免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
[原]linux 命令行下的 XML 處理利器 xmlstarlet 學(xué)習(xí)
長久以來,在shell 下處理xml一直是樓主頭疼的問題,用 regex 匹配不是不可以,但對于復(fù)雜的需求就有點捉襟見肘了,例如這樣一個問題 :查找某個元素值 item 的值等于value的節(jié)點,并把這個節(jié)點的另外一個元素值 item2 的值替換為另外一個值 value2。
對于這種需求,用 regex (sed) 處理起來很是痛苦,即便你用了 sed 的 pattern space ,也是很麻煩,光日后維護都成問題了。
昨天找了一下,有幾個候選的
xmllint
xml-coreutils
xmlstarlet
xmllint 太老了,而且文檔比較少,就一個 manual ,不太敢用。下面先說 xml-coreutils
這個東西 manual 和文檔倒還算齊全。是模擬 coreutils 包的思路,具體可以看這里。有 xml-ls、xml-cat 等命令,看起來還不錯,不過用起來就是另外一回事了,最大的問題就是 Xpath 的支持不到位 ,很多功能都沒有 :不支持屬性、不支持條件、不支持函數(shù),而且對于大文件貌似處理有問題,經(jīng)常報錯。所以最后放棄了,也不建議大家使用。例如下面的 xml ,xml-coreutils 不支持 “/bookstore/book@category ” 這種 Xpath,也就是無法識別出 category 這個屬性。。。
books.xml
Shell
1
2
3
4
5
6
7
8
9
10
11
12
<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore>
<book category="COOKING">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
</bookstore>
下面正式介紹 xmlstarlet 這個東東。xmlstarlet (官方站點點這里) 跟 xml-coreutils 不同,它并不是按照 coreutils 那種風(fēng)格,分成多個小工具的方式,而是一個大的程序,通過不同的子命令來實現(xiàn)不同的功能。這個還只是小區(qū)別,主要是 xmlstarlet 對 Xpath 規(guī)范的支持相當(dāng)?shù)轿?至少我認(rèn)為我日常需要的大部分的功能都滿足,沒有想到的也提供了),這個才是 xmlstarlet 跟 xml-coreutils 的最大區(qū)別。
XMLStarlet is a set of command line utilities (tools) which can be used to transform, query, validate, and edit XML documents and files using simple set of shell commands in similar way it is done for plain text files using UNIX grep, sed, awk, diff, patch, join, etc commands.
This set of command line utilities can be used by those who deal with many XML documents on UNIX shell command prompt as well as for automated XML processing with shell scripts.
The toolkit’s feature set includes options to:
Check or validate XML files (simple well-formedness check, DTD, XSD, RelaxNG)
Calculate values of XPath expressions on XML files (such as running sums, etc)
Search XML files for matches to given XPath expressions
Apply XSLT stylesheets to XML documents (including EXSLT support, and passing parameters to stylesheets)
Query XML documents (ex. query for value of some elements of attributes, sorting, etc)
Modify or edit XML documents (ex. delete some elements)
Format or “beautify” XML documents (as changing indentation, etc)
Fetch XML documents using http:// or ftp:// URLs
Browse tree structure of XML documents (in similar way to ‘ls’ command for directories)
Include one XML document into another using XInclude
XML c14n canonicalization
Escape/unescape special XML characters in input text
Print directory as XML document
Convert XML into PYX format (based on ESIS – ISO 8879), and vice versa
XMLStarlet command line utility is written in C and uses libxml2 and libxslt from http://xmlsoft.org/.
Implementation of extensive choice of options for XMLStarlet utility was only possible because of rich feature set of libxml2 and libxslt (many thanks to the developers of those libraries for great work).
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
install xmlstarlet 1.6.1
sed 使用變量替換和執(zhí)行外部命令
shell腳本regex正則表達式 和 字符串替換
Dom4j的使用(全而好的文章) - xhy0422 - JavaEye技術(shù)網(wǎng)站
關(guān)于Shell腳本效率優(yōu)化的一些個人想法三江小渡 | 三江小渡
linux系統(tǒng)安全shell腳本第二版
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服