製品の整数 ID を生成し、出力でそれらの整数 ID によって関連製品を参照する必要があります。入力には、この関係を表す文字列キーがあります。ご協力ありがとうございました。
入力:
<root>
<products>
<product>
<!-- a unique string key of this node between the other product nodes -->
<stringKey>AppleRef</stringKey>
<Name>Apple</Name>
<relatedProducts>
<!-- a reference to product/StringKey of Orange -->
<relatedProductStringKey>OrangeRef</relatedProductStringKey>
<!-- other related products may follow -->
</relatedProducts>
</product>
<product>
<stringKey>OrangeRef</stringKey>
<Name>Orange</Name>
<relatedProducts>
<relatedProductStringKey>AppleRef</relatedProductStringKey>
</relatedProducts>
</product>
</products>
</root>
期待される出力:
<root>
<products>
<P>
<ProductInfo>
<!-- a unique integer ID of this node between the other ProductsInfo nodes -->
<ProductID>0</ProductID>
<ProductRef>AppleRef</ProductRef>
<ProductName>Apple</ProductName>
</ProductInfo>
<R>
<ProductRelatedInfo>
<!-- a unique integer ID of this node between the other ProductRelatedInfo nodes -->
<RelatedID>0</RelatedID>
<!-- a reference to ProductInfo/ProductID of Orange -->
<RelatedProductID>1</RelatedProductID>
</ProductRelatedInfo>
<!-- other related products may follow -->
</R>
</P>
<P>
<ProductInfo>
<ProductID>1</ProductID>
<ProductRef>OrangeRef</ProductRef>
<ProductName>Orange</ProductName>
</ProductInfo>
<R>
<ProductRelatedInfo>
<RelatedID>1</RelatedID>
<RelatedProductID>0</RelatedProductID>
</ProductRelatedInfo>
</R>
</P>
</products>
</root>