我有一个客户提供的以下 XML,我需要从中提取以下项目: CustomerProductName ProductName ProductAssetName 处理每个 CustomerProducts部分作为单独的命令. 我可以访问 CustomerProducts并提取 CustomerProductN
>< CustomerProductName>
>< ProductName>
>< ProductAssetName>
处理每个< CustomerProducts>部分作为单独的命令.
我可以访问< CustomerProducts>并提取< CustomerProductName>没有问题,并迭代每个部分中的值.
但我无法看到我如何得到它下面的值.如果有人可以给我一些关于如何实现这一点的指示我会感激不尽,因为我已经尝试了一天多了.
基本代码在XML下面
<?xml version="1.0"?> <Products_Root> <Products_IPN VendorID="11344" > <CustomerProducts CustomerProductName="Test" ProductCount="7"> <Products ProductType="BOOK" ProductName="Donald" > <ProductComponents ProductAssetName="Donald.pdf" /> <ProductSpecs SpecClass="MEASUREMENT" SpecType="MARGINS" SpecValue="PER FILE"/> <ProductSpecs SpecClass="OPERATION" SpecType="BIND" SpecValue="SADDLE"/> </Products> <Products ProductType="BOOK" ProductName="Duck"> <ProductComponents ProductAssetName="Duck.pdf"/> <ProductSpecs SpecClass="MEASUREMENT" SpecType="MARGINS" SpecValue="PER FILE"/> </Products> </CustomerProducts> <CustomerProducts CustomerProductName="Test2" ProductCount="2"> <Products ProductType="BOOK" ProductName="Micky"> <ProductComponents ProductAssetName="Mouse.pdf" /> <ProductComponents ProductAssetName="Mouse.pdf" /> <ProductSpecs SpecClass="MEASUREMENT" SpecType="MARGINS" SpecValue="PER FILE"/> </Products> <CustomerProductSpecs SpecClass="OPERATION" SpecType="KITTING" SpecValue="SHRINKWRAP KIT"/> </CustomerProducts> <CustomerProducts CustomerProductName="Test3" ProductCount="6"> <Products ProductType="BOOK" ProductName="Minnie"> <ProductComponents ProductAssetName="Mouse" /> <ProductSpecs SpecClass="MEASUREMENT" SpecType="MARGINS" SpecValue="PER FILE"/> </Products> </CustomerProducts> </Products_IPN> </Products_Root>
到目前为止我的VBScript代码
Dim xmlDoc, objNodeList, plot Set xmlDoc = CreateObject("Msxml2.DOMDocument") xmlDoc.setProperty "SelectionLanguage", "XPath" xmlDoc.load("E:\dropbox\Dropbox\Hobbs\Xerox Example Files\test.xml") Set objNodeList = xmlDoc.getElementsByTagName("CustomerProducts") plot="No Value" If objNodeList.length > 0 then For each x in objNodeList JobName=x.getattribute("CustomerProductName") msgbox JobName Next Else msgbox chr(34) & "CustomerProducts" & chr(34) & " field not found." End If您已经将选择语言设置为XPath,也许您也应该使用它.