我有這種格式的XML文檔:如何轉換一個xml文檔並插入其他數據?
<?xml version="1.0" encoding="UTF-8"?>
<person name="Bob" addr_street="123 Fake St"
addr_city="Springfield" addr_state="IL"/>
我想借此數據,並通過我的代碼FigureOutZipCode(string city, string state)
功能運行。
我會那麼喜歡拿這一切的組合數據,並創建一個新的文件格式爲:
<?xml version="1.0" encoding="UTF-8"?>
<people>
<person>
<name>Bob</name>
<address>
<street>123 Fake St</address>
<city>Springfield</city>
<state>IL</state>
<zip>00000</zip>
</address>
</person>
</people>
我知道我可以只解析所有輸入XML數據的,做我的計算,然後創建一個新的輸出xml,但有沒有更好的方式去做這件事?或許像使用xslt一樣?
如果是這樣,你能提供一些關於如何做到這一點的指導嗎?
對於xslt,請參閱http://stackoverflow.com/questions/10645359/convert-xml-attributes-to-elements-xslt – 2013-04-24 21:32:07