【发布时间】:2014-03-16 05:55:00
【问题描述】:
我有以下 XML 结构:
<?xml version="1.0" encoding="utf-16"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance
" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<StoreResponse xmlns="http://www.some-site.com">
<StoreResult>
<Message />
<Code>OK</Code>
</StoreResult>
</StoreResponse>
</soap:Body>
</soap:Envelope>
我需要从本文档的Code获取 InnerText,我需要有关适当 XPATH 语句的帮助。
我真的对 XML 命名空间感到困惑。在处理另一个 XML 文档中的先前命名空间问题时,我了解到,即使 Code 前面没有任何内容(例如 ns:Code),它仍然是其父节点中 xmlns 属性定义的命名空间的一部分。现在,Code 的父节点中定义了多个 xmlns 节点。我需要在 XPATH 语句中指定的命名空间是什么?是否有“主命名空间”之类的东西?子节点是否继承其父节点的(主)命名空间?
【问题讨论】:
标签: c# xml xpath namespaces