4
주어진 XML 문서에서 다른 태그의 자식으로 사용되는 태그를 보여주는 그래프를 작성하고 싶습니다.XML 문서의 구조 그래프 만들기
나는 lxml.etree 트리에 주어진 태그 아이 태그의 고유 한 세트를 얻기 위해이 기능을 서면으로 작성했습니다 :
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
나는이 함께 사용할 수있는 범용 그래프 빌더가 거기를 어떤 다른 형식의 도트 파일이나 그래프를 만드는 함수?
나는 또한이 목적을 위해 명시 적으로 설계된 어딘가에 도구가 있다는 몰래 의심을 갖게됩니다. 그게 뭐야?