【发布时间】:2016-07-23 08:51:13
【问题描述】:
由于使用 XPath 获取具有特定属性的元素花费了太多时间,我一直在苦苦挣扎。
下面是我要从中获取元素的wsdl:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright Zuora, Inc. 2007 - 2010 All Rights Reserved. -->
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:zns="http://api.zuora.com/"
xmlns:ons="http://object.api.zuora.com/"
xmlns:fns="http://fault.api.zuora.com/"
targetNamespace="http://api.zuora.com/">
<types>
<schema attributeFormDefault="qualified" elementFormDefault="qualified" xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://object.api.zuora.com/">
<import namespace="http://api.zuora.com/" />
<complexType name="zObject">
<sequence>
<element minOccurs="0" maxOccurs="unbounded" name="fieldsToNull" nillable="true" type="string" />
<element minOccurs="0" maxOccurs="1" name="Id" nillable="true" type="zns:ID" />
</sequence>
</complexType>
<complexType name="AccountingCode" >
<complexContent>
<extension base="ons:zObject">
<sequence>
<element minOccurs="0" name="Category" nillable="true" type="string" />
<element minOccurs="0" name="CreatedById" nillable="true" type="zns:ID" />
<element minOccurs="0" name="CreatedDate" nillable="true" type="dateTime" />
<element minOccurs="0" name="GLAccountName" nillable="true" type="string" />
<element minOccurs="0" name="GLAccountNumber" nillable="true" type="string" />
<element minOccurs="0" name="Name" nillable="false" type="string" />
<element minOccurs="0" name="Notes" nillable="true" type="string" />
<element minOccurs="0" name="Status" nillable="true" type="string" />
<element minOccurs="0" name="Type" nillable="false" type="string" />
<element minOccurs="0" name="UpdatedById" nillable="true" type="zns:ID" />
<element minOccurs="0" name="UpdatedDate" nillable="true" type="dateTime" />
</sequence>
</extension>
</complexContent>
</complexType>
<complexType name="AccountingPeriod" >
<complexContent>
<extension base="ons:zObject">
<sequence>
<element minOccurs="0" name="CreatedById" nillable="true" type="zns:ID" />
<element minOccurs="0" name="CreatedDate" nillable="true" type="dateTime" />
<element minOccurs="0" name="EndDate" nillable="true" type="date" />
<element minOccurs="0" name="FiscalYear" nillable="true" type="int" />
<element minOccurs="0" name="Name" nillable="true" type="string" />
<element minOccurs="0" name="Notes" nillable="true" type="string" />
<element minOccurs="0" name="StartDate" nillable="true" type="date" />
<element minOccurs="0" name="Status" nillable="true" type="string" />
<element minOccurs="0" name="UpdatedById" nillable="true" type="zns:ID" />
<element minOccurs="0" name="UpdatedDate" nillable="true" type="dateTime" />
</sequence>
</extension>
</complexContent>
</complexType>
</schema>
</types>
</definitions>
在这个 wsdl 中定义了多个命名空间:
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:zns="http://api.zuora.com/"
xmlns:ons="http://object.api.zuora.com/"
xmlns:fns="http://fault.api.zuora.com/"
targetNamespace="http://api.zuora.com/">
下面是我非常简单的一段代码。我很确定我的问题出在命名空间上,但尽管搜索了很多尝试的解决方案,但我无法解决它:
Public Sub constituteLocalDictionnary()
Dim pathWsdlFile As String
pathWsdlFile = My.Settings.ZuoraUrlWSDL
Dim doc As New XmlDocument()
doc.Load(pathWsdlFile)
Dim nsmgr As XmlNamespaceManager = New XmlNamespaceManager(doc.NameTable)
nsmgr.AddNamespace("ns", "http://schemas.xmlsoap.org/wsdl/")
nsmgr.AddNamespace("ons", "http://object.api.zuora.com/")
Dim myXmlPath As String
myXmlPath = "//ns:complexType[@name='" & ZuoraWsdlObjectsList(1) & "']"
Dim root As XmlElement = doc.DocumentElement
Dim node As XmlNode = root.SelectSingleNode(myXmlPath, nsmgr)
End Sub
【问题讨论】:
-
我所有的礼貌公式都在复制和粘贴后用于验证这篇文章。有一些大家好...非常感谢您的帮助...类似的事情:)对于原始帖子的粗糙方面感到抱歉。
标签: xml vb.net xpath namespaces