Q:

Select a xml node with specific xmlText and attribute value in coldfusion

I have a XML document and this is the node I want to select:

Initially I tried to select it with its attribute ID as and it works fine:
<cfset local.XML = xmlParse(filePath)>       
<cfset local.header = xmlSearch(
                local.XML,
                "/FILE/COLUMNS/HEADER[@ID = 1051]"
            )> 

I am now trying to select this xml node with its xmlText as:
<cfset local.header = xmlSearch(
                local.XML,
                "/FILE/COLUMNS/HEADER[text() = '4079']"
            )>

But I am not able to select this node with its text.
What am I doing wrong?
And is it possible to select a node with specific attribute value and text in single statement?
This is sample XML:
<?xml version="1.0" encoding="UTF-8"?>
<FILE>
    <COLUMNS ID="1" xmlns="">
        <HEADER ID="1134">
            <![CDATA[11222]]>
        </HEADER>
        <HEADER ID="1135">
            <![CDATA[Test Data]]>
        </HEADER>
        <HEADER ID="1136">
            <![CDATA[Test Data]]>
        </HEADER>
        <HEADER ID="1151">
            <![CDATA[4079]]>
        </HEADER>
        <HEADER ID="1137">
            <![CDATA[Test Data]]>
        </HEADER>
        <HEADER ID="1144">
            <![CDATA[Test Data]]>
        </HEADER>
    </COLUMNS>
    <COLUMNS ID="2" xmlns="">
        <HEADER ID="1134">
            <![CDATA[11222]]>
        </HEADER>
        <HEADER ID="1135">
            <![CDATA[Test Data]]>
        </HEADER>
        <HEADER ID="1136">
            <![CDATA[Test Data]]>
        </HEADER>
        <HEADER ID="1151">
            <![CDATA[4079]]>
        </HEADER>
        <HEADER ID="1137">
            <![CDATA[4079]]>
        </HEADER>
        <HEADER ID="1144">
            <![CDATA[4079]]>
        </HEADER>
    </COLUMNS>
</FILE>

Now I want to select all HEADER nodes with xmlText = 4079.
Please help. Thanks in advance.

A:

What you can try is using the normalize-space() along with the XMLSearch you have.
<cfset search = XMLSearch(xmlobj,"//HEADER[@ID=1151][normalize-space(text())='4079']")/>

I included the ID attribute as well as the text value in my search.
This should get you the HEADER items with value of 4079 and an ID of 1151.  There are two of these in your example XML so you may have to do something more if you want a unique value like filter by COLUMNS too.
normalize-space() will trim the whitespace from the left and right side and returns the string value.

