這是上一個問題的後續操作:Write xml with a path and value。我現在想添加兩個額外的東西:1)屬性和2)與父節點的多個項目。下面是路徑的名單上有:從路徑/值列表中寫入xml
[
{'Path': 'Item/Info/Name', 'Value': 'Body HD'},
{'Path': 'Item/Info/Synopsis', 'Value': 'A great movie'},
{'Path': 'Item/Locales/Locale[@Country="US"][@Language="ES"]/Name', 'Value': 'El Grecco'},
{'Path': 'Item/Genres/Genre', 'Value': 'Action'},
{'Path': 'Item/Genres/Genre', 'Value': 'Drama'},
{'Path': 'Item/Purchases/Purchase[@Country="US"]/HDPrice', 'Value': '10.99'},
{'Path': 'Item/Purchases/Purchase[@Country="US"]/SDPrice', 'Value': '9.99'},
{'Path': 'Item/Purchases/Purchase[@Country="CA"]/SDPrice', 'Value': '4.99'},
]
應該生成XML是:
<Item>
<Info>
<Name>Body HD</Name>
<Synopsis>A great movie</Synopsis>
</Info>
<Locales>
<Locale Country="US" Language="ES">
<Name>El Grecco</Name>
</Locale>
</Locales>
<Genres>
<Genre>Action</Genre>
<Genre>Drama</Genre>
</Genres>
<Purchases>
<Purchase Country="US">
<HDPrice>10.99</HDPrice>
<SDPrice>9.99</SDPrice>
</Purchase>
<Purchase Country="CA">
<SDPrice>4.99</SDPrice>
</Purchase>
</Purchases>
</Item>
我怎麼會建了這一點?
在''項目/區域設置/區域設置[國家= 「美國」]語言= [「ES」]/Name'','Country'*爲什麼在*括號內,而'Language' *在*之外? –
@Robᵩ謝謝我更新了它。 – David542