[英]format xml, pretty print
我知道兩種“漂亮打印”或格式化 xml 的方法:
還有哪些其他免費(如啤酒)格式化程序? (除了使用javascript)
嗯,您鏈接到的身份轉換可移植到任何 XSLT 處理器(Saxon、msxml 等)。
此外,您可以查看xmllint
,它是LibXML2工具包的一部分。 --format
選項允許您漂亮地打印輸入。 類似的功能存在於XMLStarlet (它在 iirc 下使用 LibXML2)。
xmlstarlet fo
是我用來打印漂亮的東西。 Xmlstarlet有許多選項:
$ xmlstarlet fo --help
XMLStarlet Toolkit: Format XML document
Usage: xml fo [<options>] <xml-file>
where <options> are
-n or --noindent - do not indent
-t or --indent-tab - indent output with tabulation
-s or --indent-spaces <num> - indent output with <num> spaces
-o or --omit-decl - omit xml declaration <?xml version="1.0"?>
-R or --recover - try to recover what is parsable
-D or --dropdtd - remove the DOCTYPE of the input docs
-C or --nocdata - replace cdata section with text nodes
-N or --nsclean - remove redundant namespace declarations
-e or --encode <encoding> - output in the given encoding (utf-8, unicode...)
-H or --html - input is HTML
一個優秀的 XML 工程師應該能夠使用 xmlstarlet。
您可以使用http://prettydiff.com/?m=beautify不幸的是,它是用 JavaScript 編寫的,但它是一個完整的應用程序,因此您永遠不必知道這一點。 只要知道您可以在瀏覽器中運行,而無需下載或安裝任何東西。
在 python 中使用 libxml2 時:
with open(pathToSaveResult, 'w') as fd:
xmlParsed.saveTo(fd,format = libxml2.XML_SAVE_FORMAT)
編輯:看起來 libxml2 中存在一些錯誤......使用標簽 libxml2.XML_SAVE_NO_EMPTY 而不是 libxml2.XML_SAVE_FORMAT 完成了漂亮的打印
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.