Closed the question as it wasn't an error - it just isn't possible
I am trying to return a range that contains all elements in a listobject/xmlmap where a sibling element meets some criteria (a particular elements values are not empty/blank/zero-length).
If I try to return the entire element of the xmlmap, I get the range returned correctly. However as soon as I add any criteria, the range object isn't set and I get an error.
I have removed the namespace refrences throughout, to try and pin down the error, but even without namespace declarations, the error remains. The code below is a much simplified version of what I'm working with, to show the error.
XML data
<?xml version='1.0' encoding='UTF-8'?>
<ROOT>
<RECORD>
<ITEMA/>
<ITEMB>RED</ITEMB>
</RECORD>
<RECORD>
<ITEMA>A</ITEMA>
<ITEMB>BLUE</ITEMB>
</RECORD>
<RECORD>
<ITEMA>B</ITEMA>
<ITEMB>GREEN</ITEMB>
</RECORD>
</ROOT>
XSD used to set up XmlMap in Excel
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="ROOT" type="RootType"/>
<xs:complexType name="RootType">
<xs:sequence>
<xs:element name="RECORD" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="ITEMA"/>
<xs:element name="ITEMB"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>
Working VBA Code (without predicate)
Sub TestSUCCESS()
Dim rngSource As Range
Dim sSourceXPath As String
sSourceXPath = "/ROOT/RECORD/ITEMB"
Set rngSource = Sheet4.XmlDataQuery(sSourceXPath)
Debug.Print rngSource.Address
End Sub
Non-Working VBA Code (with predicate)
Sub TestERROR()
Dim rngSource As Range
Dim sSourceXPath As String
sSourceXPath = "/ROOT/RECORD/ITEMA[text()[normalize-space()]]"
Set rngSource = Sheet4.XmlDataQuery(sSourceXPath)
If Not rngSource Is Nothing Then
Debug.Print rngSource.Address
Else
Debug.Print "ERROR: rngSource isn't set"
End If
End Sub
I have also tried using the following xpath:
"/ROOT/RECORD/ITEMB[../ITEMA[string-length(text()) > 0]]"
As well as variations of the folloving just to get anything to work, but to no avail:
sSourceXPath = "/ROOT/RECORD/ITEMB[../ITEMA[.="A"]]"
All the xPath examples I've given work in Altova XMLSpy 2005.
Can anyone offer any suggestions as to where I've gone wrong ?