【发布时间】:2016-08-16 20:52:25
【问题描述】:
这是上一个问题的后续问题:Write xml with a path and value。我现在想添加两个额外的东西:1)属性和 2)具有父节点的多个项目。这是我拥有的路径列表:
[
{'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>
我将如何构建它?
【问题讨论】:
-
在
'Item/Locales/Locale[Country="US"]Language=["ES"]/Name'中,为什么Country在括号内,而Language在外? -
@Robᵩ 谢谢我更新了。