Giter Club home page Giter Club logo

xml-analyser's Introduction

xml-analyser

PyPI Changelog Tests License

A tool showing various statistics about element usage in an arbitrary XML file.

Installation

pip install xml-analyser

Or using pipx:

pipx install xml-analyser

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>

xml-analyser's People

Contributors

simonw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

xml-analyser's Issues

Use parent counts as a tie-breaker

If two elements have the same number of occurrences, I want to list the most likely to be root element (the one with the least parent elements) first. Follows on from #4.

For each child element, indicate if it's 100% present and if it can occur multiple times

e.g. for this one:

    "note": {
        "attr_counts": {},
        "child_counts": {
            "content": 2126,
            "created": 2126,
            "note-attributes": 2126,
            "resource": 2605,
            "tag": 45,
            "title": 2126,
            "updated": 2126
        },
        "count": 2126,
        "parent_counts": {
            "en-export": 2126
        }
    },

It would be useful to know that EVERY note has a content and created tag, whereas the resource tag can turn up 0 times and can also turn up more than one times.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.