0
我试图一般性地编写XML解析器来消费未知模式的提要。基本上,我想对“行”在XML文档中的位置做出最佳猜测。这里有两个例子提要:自动检测/解析XML中的重复元素('行对象')
饲料1,例如:
<xml>
<some-container-tag>
<some-row-tag>
<attribute-1>value</attribute-1>
<attribute-2>value</attribute-2>
<attribute-3>value</attribute-3>
<attribute-4>value</attribute-4>
</some-row-tag>
<some-row-tag>
<attribute-1>value</attribute-1>
<attribute-2>value</attribute-2>
<attribute-3>value</attribute-3>
<attribute-4>value</attribute-4>
</some-row-tag>
...
</some-container-tag>
</xml>
饲料2,例如:
<xml>
<some-container-tag>
<some-row-tag>
<attribute-1>value</attribute-1>
<attribute-2>value</attribute-2>
<attribute-3>value</attribute-3>
<attribute-4>value</attribute-4>
<optional-nested-attribute-set>
...
</optional-nested-attribute-set>
</some-row-tag>
<some-row-tag>
<attribute-1>value</attribute-1>
<attribute-2>value</attribute-2>
<attribute-3>value</attribute-3>
<attribute-4>value</attribute-4>
<optional-nested-attribute-set>
...
</optional-nested-attribute-set>
</some-row-tag>
...
</some-container-tag>
<some-other-container-tag>
<some-row-tag>
<attribute-1>value</attribute-1>
<attribute-2>value</attribute-2>
<attribute-3>value</attribute-3>
<attribute-4>value</attribute-4>
<optional-nested-attribute-set>
...
</optional-nested-attribute-set>
</some-row-tag>
</some-other-container-tag>
</xml>
我所做的到目前为止是横贯结构和地图的XPath来一个计数,例如第一进是这样的:
xml => 1
xml/some-container-tag => 1
xml/some-container-tag/some-row-tag => n
xml/some-container-tag/some-row-tag/attribute-1 => n
xml/some-container-tag/some-row-tag/attribute-2 => n
xml/some-container-tag/some-row-tag/attribute-3 => n
xml/some-container-tag/some-row-tag/attribute-4 => n
现在我的想法是,“基本单位”(行级)将是最低级的非叶节点,虽然我有问题(独奏开发在这里)审查这个想法。
当然,feed 2的'更'更复杂,可能有嵌套的属性(基本上是子数组),也可能有两个父列表。
这里有什么足够好的通用方法?