这是上一个问题的后续操作: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