Question

J'aimerais construire un graphique montrant quelles balises sont utilisées comme enfants dont d'autres tags dans un document XML donné.

J'ai écrit cette fonction pour obtenir l'ensemble unique de balises enfants pour une étiquette donnée dans un arbre LXML.ETRE:

def iter_unique_child_tags(root, tag):
    """Iterates through unique child tags for all instances of tag.

    Iteration starts at `root`.
    """
    found_child_tags = set()
    instances = root.iterdescendants(tag)
    from itertools import chain
    child_nodes = chain.from_iterable(i.getchildren() for i in instances)
    child_tags = (n.tag for n in child_nodes)
    for t in child_tags:
        if t not in found_child_tags:
            found_child_tags.add(t)
            yield t

Y a-t-il un constructeur de graphiques à usage général que je pourrais utiliser avec cette fonction pour créer un dotfile ou un graphique dans un autre format?

J'obtiens aussi la suspicion qui se dessèche qu'il existe un outil quelque part explicitement conçu à cette fin;que pourrait-il être?

Était-ce utile?

La solution

J'ai fini par utiliser python-graphique .J'ai aussi fini par utiliser argparse pour créer une interface de ligne de commande qui tire des bits de base deInfo de XML Documents et construit des images de graphique dans les formats pris en charge par pydot .C'est ce qu'on appelle xmlearn et est en quelque sorte utile:

usage: xmlearn [-h] [-i INFILE] [-p PATH] {graph,dump,tags} ...

optional arguments:
  -h, --help            show this help message and exit
  -i INFILE, --infile INFILE
                        The XML file to learn about. Defaults to stdin.
  -p PATH, --path PATH  An XPath to be applied to various actions.
                        Defaults to the root node.

subcommands:
  {graph,dump,tags}
    dump                Dump xml data according to a set of rules.
    tags                Show information about tags.
    graph               Build a graph from the XML tags relationships.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top