分析任意XML文件的结构
项目描述
xml-analyser
一个工具,可以显示任意XML文件中元素使用的各种统计数据。
用法
xml-analyser example.xml
如果example.xml
看起来像这样
<example>
<foo>
<bar a="1" b="2">
<baz>This has text</baz>
</bar>
</foo>
<foo>
<bar a="1" b="2" c="3">
<baz>More text here</baz>
</bar>
<baz d="1" />
</foo>
</example>
xml-analyzer example.xml
输出如下
{
"example": {
"count": 1,
"parent_counts": {},
"attr_counts": {},
"child_counts": {
"foo": 2
}
},
"foo": {
"count": 2,
"parent_counts": {
"example": 2
},
"attr_counts": {},
"child_counts": {
"bar": 2,
"baz": 1
}
},
"bar": {
"count": 2,
"parent_counts": {
"foo": 2
},
"attr_counts": {
"a": 2,
"b": 2,
"c": 1
},
"child_counts": {
"baz": 2
}
},
"baz": {
"count": 3,
"parent_counts": {
"bar": 2,
"foo": 1
},
"attr_counts": {
"d": 1
},
"child_counts": {},
"count_with_text": 2,
"max_text_length": 14
}
}
截断XML内容
使用--truncate
选项的工作方式不同:传递给此工具的XML文件将被截断,通过找到具有两个或更多相同类型子元素的元素,并截断到仅包含这两个元素。
这可以将大型XML文件减少为更易于理解的形式。
给定一个如下的示例文档
<example>
<atop title="Example 1" />
<atop title="Example 2" />
<atop title="Example 3" />
<atop title="Example 4" />
<foo>
<bar a="1" b="2">
<baz>This has text</baz>
</bar>
<bar a="2" b="2">
<baz>This has text</baz>
</bar>
<bar a="3" b="2">
<baz>This has text</baz>
</bar>
<bar a="4" b="2">
<baz>This has text</baz>
</bar>
</foo>
<foo>
<bar a="1" b="2" c="3">
<baz>More text here</baz>
</bar>
<baz d="1" />
</foo>
<foo>
<bar a="1" b="2" c="3">
<baz>More text here</baz>
</bar>
<baz d="1" />
</foo>
</example>
以下命令
xml-analyser example.xml --truncate
将返回以下内容
<example>
<atop title="Example 1" />
<atop title="Example 2" />
<foo>
<bar a="1" b="2">
<baz>This has text</baz>
</bar>
<bar a="2" b="2">
<baz>This has text</baz>
</bar>
</foo>
<foo>
<bar a="1" b="2" c="3">
<baz>More text here</baz>
</bar>
<baz d="1" />
</foo>
</example>
项目详情
下载文件
下载适用于您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。
源分布
xml-analyser-1.3.tar.gz (7.6 kB 查看哈希值)
构建分布
xml_analyser-1.3-py3-none-any.whl (8.2 kB 查看哈希值)