如何生成仅含唯一标签与属性的XML结构树?求工具或Python方案
Tool or Python Script to Generate Unique-Tag XML Structure Tree (No Duplicates, No Text) for Handwriting XSD/DTD on Mac
I'm currently hand-writing XSD and DTD schemas to validate XML files, but I'm stuck with two major pain points:
- XSD generators like Oxygen have been a terrible experience—they just don't fit what I need at all.
- The sample XML I'm working with is massive: one of its elements contains 4312 child elements, with tons of duplicate tags and attributes. Filtering out these duplicates while writing XSD manually is incredibly tedious and time-consuming.
What I need is a way to generate an XML structure tree that only keeps unique tags and attributes, with no text content whatsoever. It can be in XML format or an ASCII tree structure. Let me give an example to clarify:
Original XML snippet:
<root> <item id="1">Apple</item> <item id="2">Banana</item> <category name="fruit"> <item id="3">Orange</item> </category> </root>Desired output (XML format):
<root> <item id=""/> <category name=""> <item id=""/> </category> </root>Or ASCII tree structure:
root ├─ item [id] └─ category [name] └─ item [id]
I've tried using Power Query to handle this before, but the results were pretty bad—there were still lots of duplicates and unnecessary content left. So I'm reaching out for help:
- Are there any Mac-compatible online or desktop tools that can do this?
- Can this be implemented with Python's ElementTree library? If yes, could someone share a sample script?
- Any other suggestions to optimize the process of hand-writing XSD/DTD are also more than welcome!
内容的提问来源于stack exchange,提问作者Raymond_90
相关产品推荐
相关产品推荐

