• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Cannot xmlSearch in CF2016

New Here ,
Jul 11, 2018 Jul 11, 2018

Copy link to clipboard

Copied

Hello all

I have this xml file:

<?xml version="1.0" encoding="utf-8"?>

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

    <soap:Body>

        <SoapRequestResponse xmlns="http://tempuri.org/">

            <SoapRequestResult>

                <ExtensionData />

                <Successful>Y</Successful>

                <ResponseCode>9999</ResponseCode>

                <HeaderMessage>Success</HeaderMessage>

                <ItemMessages />

                <ClientTracking>xxxxx</ClientTracking>

                <TotalTax>7.32641</TotalTax>

                <TransId>1234567890</TransId>

                <GroupList>

                    <Group>

                        <ExtensionData />

                        <LineNumber>1</LineNumber>

                        <StateCode>NY</StateCode>

                        <InvoiceNumber>12345</InvoiceNumber>

                        <CustomerNumber>98765</CustomerNumber>

                        <TaxList>

                            <Tax>

                                <ExtensionData />

                                <TaxTypeCode>101</TaxTypeCode>

                                <TaxTypeDesc>STATE SALES TAX</TaxTypeDesc>

                                <TaxAmount>1.17698</TaxAmount>

                                <Revenue>24.99</Revenue>

                                <CountyName>SUFFOLK</CountyName>

                                <CityName>AMITY HARBOR</CityName>

                                <TaxRate>0.040000000000</TaxRate>

                                <PercentTaxable>1.000000</PercentTaxable>

                                <FeeRate>0</FeeRate>

                                <RevenueBase>29.42450</RevenueBase>

                                <TaxOnTax>0.17738</TaxOnTax>

                            </Tax>

                            <Tax>

                                <ExtensionData />

                                <TaxTypeCode>202</TaxTypeCode>

                                <TaxTypeDesc>COUNTY SALES TAX</TaxTypeDesc>

                                <TaxAmount>1.25055</TaxAmount>

                                <Revenue>24.99</Revenue>

                                <CountyName>SUFFOLK</CountyName>

                                <CityName>AMITY HARBOR</CityName>

                                <TaxRate>0.042500000000</TaxRate>

                                <PercentTaxable>1.000000</PercentTaxable>

                                <FeeRate>0</FeeRate>

                                <RevenueBase>29.42471</RevenueBase>

                                <TaxOnTax>0.18847</TaxOnTax>

                            </Tax>

                        </TaxList>

                    </Group>

                </GroupList>

            </SoapRequestResult>

        </SoapRequestResponse>

    </soap:Body>

</soap:Envelope>

In CF9 - i used these commands after calling cfhttp:

<cfset xmlParseIn = XmlParse(taxResponse.filecontent)>

<cfset responseResult = xmlSearch(xmlParseIn,"//*[ local-name() = 'SoapRequestResult' ]") />

Which produced an array that I would then deal with in subsequent code.

Now in CF2016 (using same xmlParse and xmlSearch) I get this error:

Detail: ColdFusion is unable to process the result of the XPath search. You may have an undefined variable in the xpath expression.

Message: Unable to process the result of the XMLSearch for ''.

Can someone give me some direction. We were forced on CF2016, after a CF9 crash, so now I'm under the gun!

thanks in advance

Artie

Views

1.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Jul 11, 2018 Jul 11, 2018

Not sure you need XMLSearch there, as long as the XML structure is the same, you can probably just do:

<cfset responseResult = xmlParseIn.XmlRoot["soap:Body"].SoapRequestResponse.SoapRequestResult>

The only difference is that responseResult will not be an array, it will just be the XML Node structure.  If you want the array it would probably be:

<cfset responseResult = xmlParseIn.XmlRoot["soap:Body"].SoapRequestResponse.XmlChildren>

Votes

Translate

Translate
Enthusiast ,
Jul 11, 2018 Jul 11, 2018

Copy link to clipboard

Copied

Not sure you need XMLSearch there, as long as the XML structure is the same, you can probably just do:

<cfset responseResult = xmlParseIn.XmlRoot["soap:Body"].SoapRequestResponse.SoapRequestResult>

The only difference is that responseResult will not be an array, it will just be the XML Node structure.  If you want the array it would probably be:

<cfset responseResult = xmlParseIn.XmlRoot["soap:Body"].SoapRequestResponse.XmlChildren>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 11, 2018 Jul 11, 2018

Copy link to clipboard

Copied

That worked great! thanks!

one last thing, i also noticed that further down i am doing this:

<cfloop index="z" array="#xmlSearch(xmlParseIn,"//*[ local-name() = 'Group' ]")#">

</cfloop>

i can't seem to apply your example to this

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 11, 2018 Jul 11, 2018

Copy link to clipboard

Copied

You might expirement with cfdump to see how to traverse the XML, but it is essentially a structure, so since GroupList is a child of SoapRequestResult and you want an array of Group tags (which is a child of GroupList, you should be able to get an array of Group tags with this:

xmlParseIn.XmlRoot["soap:Body"].SoapRequestResponse.SoapRequestResult.GroupList.XmlChildren

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 11, 2018 Jul 11, 2018

Copy link to clipboard

Copied

Adding to Pete's helpful reply, I would also ask if you have confirmed with 100 %certainty that the cfhttp.filecontent is exactly the same in your two CF versions.  It's possible that something unexpected is causing it NOT to be identical. 

And look at all the content (in a cfdump), because the problem may be at the end of the content, even if the beginning looks the same.


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 11, 2018 Jul 11, 2018

Copy link to clipboard

Copied

Yes Charlie - the cfhttp.filecontent are identical - but good point - i hadn't thought of that

thanks!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 11, 2018 Jul 11, 2018

Copy link to clipboard

Copied

Again, while I leave it to Pete to discuss with you the alternatives for what you're trying, I want to focus solely on the original issue, where you felt that something working in 9 does not work in 2016.

So you confirm that the dump of the cfhttp.filecontent (that you're passing to xmlparse) is identical. Ok, we'll have to take your word for that. 🙂

The next question would be whether you dumped the result of that parse, in your case xmlParseIn? Did you view that in CF2016? How does it look? And did you compare it to what you'd see in CF9?

Finally, just as another way to demonstrate that what you have shared SHOULD (and DOES) work in CF2016, I have put together this example. Note how I pass your XML to CFSavecontent, and then I pass the result of THAT to the XMLParse, and then I xmlsearch that. And it DOES work, producing a result and not throwing an error. (Note that one has to leave the opening ?xml element off when doing this. If instead, I had passed this XML to the CFXML tag, that WOULD accept the ?xml prologue line, and would negate need of using xmlparse, of course, as CFXML would turn the result into an xml object, inherently.)

(I'll add also that I don't have a CF9 readily available to try things--and I was not at my computer when I replied initially this morning, so I had not been able to test this then.)

If you try it as well, does it produce in the end the result you'd seen in CF9?

<cfsavecontent variable="sample">

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

    <soap:Body>

        <SoapRequestResponse xmlns="http://tempuri.org/">

            <SoapRequestResult>

                <ExtensionData />

                <Successful>Y</Successful>

                <ResponseCode>9999</ResponseCode>

                <HeaderMessage>Success</HeaderMessage>

                <ItemMessages />

                <ClientTracking>xxxxx</ClientTracking>

                <TotalTax>7.32641</TotalTax>

                <TransId>1234567890</TransId>

                <GroupList>

                    <Group>

                        <ExtensionData />

                        <LineNumber>1</LineNumber>

                        <StateCode>NY</StateCode>

                        <InvoiceNumber>12345</InvoiceNumber>

                        <CustomerNumber>98765</CustomerNumber>

                        <TaxList>

                            <Tax>

                                <ExtensionData />

                                <TaxTypeCode>101</TaxTypeCode>

                                <TaxTypeDesc>STATE SALES TAX</TaxTypeDesc>

                                <TaxAmount>1.17698</TaxAmount>

                                <Revenue>24.99</Revenue>

                                <CountyName>SUFFOLK</CountyName>

                                <CityName>AMITY HARBOR</CityName>

                                <TaxRate>0.040000000000</TaxRate>

                                <PercentTaxable>1.000000</PercentTaxable>

                                <FeeRate>0</FeeRate>

                                <RevenueBase>29.42450</RevenueBase>

                                <TaxOnTax>0.17738</TaxOnTax>

                            </Tax>

                            <Tax>

                                <ExtensionData />

                                <TaxTypeCode>202</TaxTypeCode>

                                <TaxTypeDesc>COUNTY SALES TAX</TaxTypeDesc>

                                <TaxAmount>1.25055</TaxAmount>

                                <Revenue>24.99</Revenue>

                                <CountyName>SUFFOLK</CountyName>

                                <CityName>AMITY HARBOR</CityName>

                                <TaxRate>0.042500000000</TaxRate>

                                <PercentTaxable>1.000000</PercentTaxable>

                                <FeeRate>0</FeeRate>

                                <RevenueBase>29.42471</RevenueBase>

                                <TaxOnTax>0.18847</TaxOnTax>

                            </Tax>

                        </TaxList>

                    </Group>

                </GroupList>

            </SoapRequestResult>

        </SoapRequestResponse>

    </soap:Body>

</soap:Envelope>

</cfsavecontent>

<cfdump var="#sample#">

<cfset xmlParseIn = XmlParse(sample)>

<cfdump var="#xmlParseIn#">

<cfset responseResult = xmlSearch(xmlParseIn,"//*[ local-name() = 'SoapRequestResult' ]") />

<cfdump var="#responseResult#">


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 12, 2018 Jul 12, 2018

Copy link to clipboard

Copied

Charlie

thanks for your response. Maybe there is a setting on my CF server that is wrong or something because in my server it just doesn't work. I have copied exactly what you have here and ran it on my server and I still get this error:

Detail    ColdFusion is unable to process the result of the XPath search. You may have an undefined variable in the xpath expression.

ErrNumber    0

Message    Unable to process the result of the XMLSearch for ''.

Any help would be great I use this method in many many places and we were forced to move to CF2016 before we were ready and some customer's functions that use this do not work, so the pressure is on!

thanks!

Artie

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 13, 2018 Jul 13, 2018

Copy link to clipboard

Copied

LATEST

I would not expect it to be a setting, no. I am aware of none that would influence that code as I shared it.

So instead, I would wonder if perhaps you had someone apply an update to CF2016 at some point, and it failed (even if only very subtly and only showing up now in this test of yours). I have a blog post talking through how to check for and resolve that, which would only take you a few minutes to do:

http://www.carehart.org/blog/client/index.cfm/2016/9/6/solve_common_problems_with_CF_updates_in_10_and_above

Let us know what you find.

/charlie


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation