c#中特定XML节点的命名空间(Namespace of specific XML Node in c#)

编程入门 行业动态 更新时间:2024-10-27 18:27:50
c#中特定XML节点的命名空间(Namespace of specific XML Node in c#)

我有以下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语句中指定的命名空间是什么? 有没有“主命名空间”这样的东西? 子节点是否继承了父节点的(主)名称空间?

I have the following XML structure:

<?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>

I need to get the InnerText from Codeout of this document and I need help with the appropriate XPATH statement.

I'm really confused by XML namespaces. While working on a previous namespace problem in another XML document, I learned, that even if there's nothing in front of Code (e.g. ns:Code), it is still part of a namespace defined by the xmlns attribute in its parent node. Now, there are multiple xmlns nodes defined in parents of Code. What is the namespace that I need to specify in an XPATH statement? Is there such a thing as a "primary namespace"? Do childnodes inherit the (primary) namespace of it's parents?

最满意答案

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

The namespace of the <Code> element is http://www.some-site.com. xmlsn:xxx means that names prefixed by xxx: (like soap:Body) have that namespace. xmlns by itself means that this is the default namespace for names without any prefix.

更多推荐

本文发布于:2023-08-01 15:03:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1360095.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:节点   空间   XML   Node   specific

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!