我有以下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.
更多推荐
发布评论