用法:
xml.etree.ElementTree.canonicalize(xml_data=None, *, out=None, from_file=None, **options)
C14N 2.0 變換函數。
規範化是一種以允許byte-by-byte 比較和數字簽名的方式規範化 XML 輸出的方法。它降低了 XML 序列化程序的自由度,而是生成了更受約束的 XML 表示。主要限製涉及命名空間聲明的放置、屬性的順序和可忽略的空格。
此函數將 XML 數據字符串 (
xml_data
) 或文件路徑或 file-like 對象 (from_file
) 作為輸入,將其轉換為規範形式,並使用out
文件(-like)將其寫出對象(如果提供),否則將其作為文本字符串返回。輸出文件接收文本,而不是字節。因此,它應該使用utf-8
編碼以文本模式打開。典型用途:
xml_data = "<root>...</root>" print(canonicalize(xml_data)) with open("c14n_output.xml", mode='w', encoding='utf-8') as out_file: canonicalize(xml_data, out=out_file) with open("c14n_output.xml", mode='w', encoding='utf-8') as out_file: canonicalize(from_file="inputfile.xml", out=out_file)
配置
options
如下:with_comments
:設置為 true 以包含評論(默認值:false)strip_text
:設置為 true 以去除文本內容前後的空格(默認:假)
rewrite_prefixes
:設置為 true 以將命名空間前綴替換為 “n{number}”(默認:假)
qname_aware_tags
:一組 qname 感知標記名稱,其中前綴應在文本內容中替換(默認:空)
qname_aware_attrs
:一組 qname 感知屬性名稱,其中前綴應在文本內容中替換(默認:空)
exclude_attrs
:一組不應序列化的屬性名稱exclude_tags
:一組不應序列化的標簽名稱
在上麵的選項列表中,“a set” 指的是任何字符串集合或可迭代字符串,不需要排序。
3.8 版中的新函數。
相關用法
- Python xml.etree.ElementTree.XMLParser用法及代碼示例
- Python xml.etree.ElementTree.Element用法及代碼示例
- Python xml.parsers.expat.ExpatError.code用法及代碼示例
- Python xml.parsers.expat.ParserCreate用法及代碼示例
- Python xml.dom.pulldom.DOMEventStream.expandNode用法及代碼示例
- Python xdrlib.Packer.pack_list用法及代碼示例
- Python torch.distributed.rpc.rpc_async用法及代碼示例
- Python torch.nn.InstanceNorm3d用法及代碼示例
- Python sklearn.cluster.MiniBatchKMeans用法及代碼示例
- Python pandas.arrays.IntervalArray.is_empty用法及代碼示例
- Python tf.compat.v1.distributions.Multinomial.stddev用法及代碼示例
- Python numpy.less()用法及代碼示例
- Python tf.compat.v1.distribute.MirroredStrategy.experimental_distribute_dataset用法及代碼示例
- Python Sympy Permutation.list()用法及代碼示例
- Python dask.dataframe.Series.apply用法及代碼示例
- Python scipy.ndimage.binary_opening用法及代碼示例
- Python pyspark.pandas.Series.dropna用法及代碼示例
- Python torchaudio.transforms.Fade用法及代碼示例
- Python dask.dataframe.to_records用法及代碼示例
- Python pyspark.pandas.groupby.SeriesGroupBy.unique用法及代碼示例
注:本文由純淨天空篩選整理自python.org大神的英文原創作品 xml.etree.ElementTree.canonicalize。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。