我遇到了MSXML2.DOMDocument.SelectNodes函数的问题。我的XML文件如下:
<?xml version="1.0" encoding="utf-8"?>
<Report xsi:schemaLocation="PCVManifestReport http://ritenetdb-prod.aodc.slb.com/ReportServer?%2FRITENETReports%2FPCVManifestReport&rs%3AFormat=XML&rc%3ASchema=True" Name="PCVManifestReport" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="PCVManifestReport">
<Tablix1>
<Details_Collection>
<Details Textbox24="CONTAINER" Serial_No="7345" Remarks="General transportation container. Alternate codes are: Container, Container-Mini, Container-Modular, Container-Open, Container-Closed, Container-HalfHeight, Container-Food, Container-Box, Container-Skid, Basket, Pallet, Rack - Location to adjust Maintenance Events Certification Lifting, Cert-NDT etc as per Country/SLB standard applied." Item_Count="6" Transport_Index="234.60" Seal="" />
<Details Textbox24="CONTAINER" Serial_No="28056-I" Remarks="General transportation container. Alternate codes are: Container, Container-Mini, Container-Modular, Container-Open, Container-Closed, Container-HalfHeight, Container-Food, Container-Box, Container-Skid, Basket, Pallet, Rack - Location to adjust Maintenance Events Certification Lifting, Cert-NDT etc as per Country/SLB standard applied." Seal="" />
<Details Textbox24="BUNKER" Serial_No="EXPS-SEW 14" Remarks="Explosive bunker used for wellsite storage and transport." Seal="" />
</Details_Collection>
</Tablix1>
<Tablix2>
<Details1_Collection>
<Details1 Textbox60="">
<Tablix3 Textbox40="CONTAINER,7345">
<Details2_Collection>
<Details2 Asset_Code="EQF-38" Serial_No1="38752" Remarks1="1-11/16 IN. DIA STEEL WEIGHT BAR, STD SERVICE. RATED TO 20000 PSI & 450 DEGF. LENGTH 48.4 IN., WEIGHT 30.4 LBS." Ship_Weight="0.00" Textbox47="No" />
<Details2 Asset_Code="EQF-38" Serial_No1="GB3802" Remarks1="1-11/16 IN. DIA STEEL WEIGHT BAR, STD SERVICE. RATED TO 20000 PSI & 450 DEGF. LENGTH 48.4 IN., WEIGHT 30.4 LBS." Ship_Weight="0.00" Textbox47="No" />
<Details2 Asset_Code="COL-TRX" Serial_No1="4702904" Remarks1="8 RING COLLECTOR, MADE BY TROLEX (third party) generally used in the North sea. Old FCC Part <NA>" Textbox47="No" />
<Details2 Asset_Code="WPSA-BA" Serial_No1="153" Remarks1="1-11/16" Wireline Perforating Shock Absorber (WPSA-BA)" Textbox47="No" />
<Details2 Asset_Code="PEH-EFA" Serial_No1="2528" Remarks1="PEH-EFA, HEAD, 1-3/8 FOR FLEX Weak Point" Ship_Weight="0.00" Textbox47="No" />
<Details2 Asset_Code="PEH-EFA" Serial_No1="2535" Remarks1="PEH-EFA, HEAD, 1-3/8 FOR FLEX Weak Point" Ship_Weight="0.00" Textbox47="No" />
</Details2_Collection>
</Tablix3>
</Details1>
</Details1_Collection>
</Tablix2>
</Report>
我文件的标题部分就像这样
Dim RITEmanifest As MSXML2.DOMDocument
Set RITEmanifest = New DOMDocument
RITEmanifest.async = False
RITEmanifest.Load("path to file")
RITEmanifest.setProperty "SelectionLanguage", "XPath"
所以现在我可以通过“硬编码”方式浏览节点而没有任何问题
For Each node In RITEmanifest.DocumentElement.ChildNodes(0).ChildNodes(0).ChildNodes
Debug.Print node.Attributes.getNamedItem("Serial_No").value
Next
但是使用SelectNodes不会返回任何节点
Debug.Print RITEmanifest.SelectNodes("Details").Length
知道为什么会这样吗?