gpt4 book ai didi

c# - c#中特定XML节点的命名空间

转载 作者:行者123 更新时间:2023-12-04 17:03:55 25 4
gpt4 key购买 nike

我有以下 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 namespace 感到困惑。在处理另一个 XML 文档中以前的 namespace 问题时,我了解到,即使 Code 前面没有任何内容(例如 ns:Code ),它仍然是由其父节点中的 xmlns 属性定义的命名空间的一部分。现在,在 Code 的父节点中定义了多个 xmlns 节点。 .我需要在 XPATH 语句中指定的命名空间是什么?有没有“主命名空间”这样的东西?子节点是否继承其父节点的(主要)命名空间?

最佳答案

元素的命名空间是 http://www.some-site.com . xmlsn:xxx 表示以 xxx: 为前缀的名称(如soap:Body)具有该命名空间。 xmlns 本身意味着这是没有任何前缀的名称的默认命名空间。

关于c# - c#中特定XML节点的命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21820567/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com