Analyse the structure of an arbitrary XML file
Project description
xml-analyser
A tool showing various statistics about element usage in an arbitrary XML file.
Usage:
xml-analyser example.xml
If example.xml
looks like this:
<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
outputs this:
{
"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
}
}
Truncating the XML instead
The --truncate
option works differently: the XML file passed to this tool will be truncated, by finding any elements with more than two child elements of the same type and truncating to just those two elements.
This can reduce a large XML file to something that's easier to understand.
Given an example document like this one:
<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>
The following command:
xml-analyser example.xml --truncate
Will return the following:
<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>
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
xml-analyser-1.3.tar.gz
(7.6 kB
view hashes)
Built Distribution
Close
Hashes for xml_analyser-1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed111169b963f0a47aa7114d6eed113dac5ad2528d2005a4ba7bf4f1899310a8 |
|
MD5 | 21ad0876433b06df227b65004ca0db24 |
|
BLAKE2b-256 | ba1ca94d746c0325d613d05beb70c1b59b6bad1795cedbaa0350eddab2b8d975 |