Ich habe seit zu viele Stunden zu kämpfen, um das Element mit einem bestimmten Attribut mit XPath zu bekommen.Access-Element mit einem bestimmten Attribut mit XPath in VB.net
Es folgt die WSDL-Datei aus dem ich das Element erhalten möchten:
<?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>
Es gibt mehrere Namespace in dieser WSDL-Datei definiert werden:
<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/">
hier unter meinem sehr einfaches Stück Code ist. Iam ziemlich sicher, dass mein Problem auf Namespace ist aber trotz eines versuchen zahlreiche Lösung suchen ich es nicht lösen konnte:
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
Alle meine höfliche Formel nach dem Kopieren und Einfügen t gegangen o validiere diesen Beitrag. Es gab einige Hallo alle ... Vielen Dank für jede Hilfe ... solche Sachen :) Sorry für den rought Aspekt des ursprünglichen Beitrags. – stef