我遇到了一些不寻常的问题。我的任务是“结构化 XML”。这是一个输入 XML(示例):
<documents>
<document>Review</document>
<document_id>REV#1</document_id>
<item>List of terms</item>
<item_id>10</item_id>
<item_description>Terms used in documents</item_description>
<item_attribute>Term</item_attribute>
<item_attribute_name>SA</item_attribute_name>
<item_attribute_value>Some Attribute</item_attribute_value>
<item_attribute_name>SOA</item_attribute_name>
<item_attribute_value>Some Other Attribute</item_attribute_value>
<document>Interface</document>
<document_id>AC-163</document_id>
<item>List of terms</item>
<item_id>15</item_id>
<item_description>Another item</item_description>
<item_attribute>Term</item_attribute>
<item_attribute_name>Name#1</item_attribute_name>
<item_attribute_value>Att#1</item_attribute_value>
<item_attribute_name>Name#2</item_attribute_name>
<item_attribute_value>Att#2</item_attribute_value>
</documents>
我应该做的是将其转换为以下实体结构:
文档 1..* 文档 1..1 项目 1..* 项目 1..1 属性 1..* 属性
这意味着:元素'documents'可能包含许多'document','document'仅包含一个名为'items'的元素,元素'items'可能包含许多元素'item',等等。
上述示例的预期输出为:
<documents>
<document>
<document_id>REV#1</document_id>
<items>
<item>
<id>10</id>
<description>Terms used in documents</description>
<attributes>
<attribute>
<name>SA</name>
<value>Some Attribute</value>
</attribute>
<attribute>
<name>SOA</name>
<value>Some Other Attribute</value>
</attribute>
</attributes>
</item>
</items>
</document>
<document>
<document_id>AC-163</document_id>
<items>
<item>
<id>15</id>
<description>Another item</description>
<attributes>
<attribute>
<name>Name#1</name>
<value>Att#1</value>
</attribute>
<attribute>
<name>Name#2</name>
<value>Att#2</value>
</attribute>
</attributes>
</item>
</items>
</document>
</documents>
我在这项任务中遇到了一些麻烦……请问您有什么帮助吗?这是一些不寻常的“结构化”xml - 你有什么想法吗?
此致!