【发布时间】:2014-09-10 14:46:29
【问题描述】:
我有包含 xml 命名空间的 xml。我需要从它的 xml 节点获取价值
<personxml:person xmlns:personxml="http://www.your.example.com/xml/person" xmlns:cityxml="http://www.my.example.com/xml/cities">
<personxml:name>Rob</personxml:name>
<personxml:age>37</personxml:age>
<cityxml:homecity>
<cityxml:name>London</cityxml:name>
<cityxml:lat>123.000</cityxml:lat>
<cityxml:long>0.00</cityxml:long>
</cityxml:homecity>
现在我想将标签<cityxml:lat> 的值设为123.00
代码:
string xml = "<personxml:person xmlns:personxml='http://www.your.example.com/xml/person' xmlns:cityxml='http://www.my.example.com/xml/cities'><personxml:name>Rob</personxml:name><personxml:age>37</personxml:age><cityxml:homecity><cityxml:name>London</cityxml:name><cityxml:lat>123.000</cityxml:lat><cityxml:long>0.00</cityxml:long></cityxml:homecity></personxml:person>";
var elem = XElement.Parse(xml);
var value = elem.Element("OTA_personxml/cityxml:homecity").Value;
我遇到的错误
The '/' character, hexadecimal value 0x2F, cannot be included in a name.
【问题讨论】:
-
试试这样的东西怎么样
elem.SelectSingleNode("/cityxml:homecity/@value").Value