我有以下XML:
<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">
<cbc:CustomizationID xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">urn:cen.eu:en16931:2017#compliant#urn:efactura.mfinante.ro:CIUS-RO:1.0.0</cbc:CustomizationID>
<cac:AccountingSupplierParty xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2">
<cac:Party>
<cac:PostalAddress>
<cbc:StreetName xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">xxxxxx 8</cbc:StreetName>
<cbc:CityName xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">Bacau</cbc:CityName>
<cbc:PostalZone xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">600093</cbc:PostalZone>
<cbc:CountrySubentity xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">RO-BC</cbc:CountrySubentity>
<cac:Country>
<cbc:IdentificationCode xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">RO</cbc:IdentificationCode>
我想要"IdentificationCode"在树枝上党 PostalAddress 国家发票 AccountingSupplierParty IdentificationCode
我试着:
Dim dom As New MSXML2.DOMDocument60
Dim nod As IXMLDOMNode
Dim branch As String
Dim Ns As String
Ns = "xmlns:cbc='urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2' xmlns:cac='urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2'"
With dom
.SetProperty "SelectionNamespaces", Ns
.async = False
.Load xFile
End With
'here was the answear: "/Invoice" TO "//"
branch = "//cac:AccountingSupplierParty/cac:Party/cac:PostalAddress/cac:Country/cbc:IdentificationCode"
Set nod = dom.selectSingleNode(branch)
If Not nod Is Nothing Then Stop
Set dom = Nothing
问题是nod
总是什么都没有。
供您参考,如果您将来有这样的"默认"名称空间(注意此名称空间上没有别名)
<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">
…然后,您可以创建一个虚拟别名,同时将其包含在名称空间列表中:
Ns = "xmlns:xxx='urn:oasis:names:specification:ubl:schema:xsd:Invoice-2' " & _
"xmlns:cbc='urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2' " & _
"xmlns:cac='urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2'"
,然后用Invoice
包含假别名:
branch = "/xxx:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PostalAddress/cac:Country/cbc:IdentificationCode"
我可以用你的XML。