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的'更'更復雜,可能有嵌套的屬性(基本上是子數組),也可能有兩個父列表。
這裏有什麼足夠好的通用方法?