Trying to pull out all the product names from the tag <NameProduct>
, but the problem is that you need to pull out all the names of the products, which lie only in the interval <Product>...<PostAll>
.
Below is a sample XML:
<?xml version="1.0" encoding="UTF-8"?>
<Products>
<Product>
<NameProduct>PRODUCT NAME 1</NameProduct>
<CodeProduct>PRODUCT CODE 1</CodeProduct>
<CodePlant>1111111111111111</CodePlant>
<NameDesc>DESCRIPTION POS 1</NameDesc>
<PostAll>
<Post>
<NameProduct>M1</NameProduct>
<CodeProduct>M1</CodeProduct>
<CodePlant>1</CodePlant>
<NameDesc>??-1</NameDesc>
</Post>
<Post>
<NameProduct>M2</NameProduct>
<CodeProduct>M2</CodeProduct>
<CodePlant>2</CodePlant>
<NameDesc>??-2</NameDesc>
</Post>
</PostAll>
</Product>
<Product>
<NameProduct>PRODUCT NAME 2</NameProduct>
<CodeProduct>PRODUCT CODE 2</CodeProduct>
<CodePlant>2222222222222222</CodePlant>
<NameDesc>DESCRIPTION POS 2</NameDesc>
<PostAll>
<Post>
<NameProduct>M3</NameProduct>
<CodeProduct>M3</CodeProduct>
<CodePlant>3</CodePlant>
<NameDesc>??-3</NameDesc>
</Post>
<Post>
<NameProduct>M4</NameProduct>
<CodeProduct>M4</CodeProduct>
<CodePlant>4</CodePlant>
<NameDesc>??-4</NameDesc>
</Post>
</PostAll>
</Product>
</Products>
Below is a sample code:
Dim node
Dim nodes
Dim query
Dim xml
Dim i
Dim attrs
Dim ConfigFile
Set xml = CreateObject("Msxml2.DOMDocument.3.0")
ConfigFile = "C:\ProgramData\xmlfile.xml" ' Configuration file path
Dim ok
ok = xml.Load(ConfigFile)
If (Not ok) Then
MsgBox("File configuration failed!")
Exit Sub
Else
xml.SetProperty "SelectionLanguage", "XPath"
query = "NameProduct"
Set nodes = xml.SelectNodes(query)
The method "XPath" does not work for me, apparently due to the fact that XML is missing attribute names.
Tell me how to return all the matches in a given interval XML?