Solved

Coldfusion - XMLSearch Help

Posted on 2009-06-30
6
852 Views
Last Modified: 2012-05-07
I have the XMl below returned from a Soap request.  I'm interested in the 'SalesLeadsStatisticsRecord' node (and elements below it).  I'm struggling to get my head around exactly what I need to be putting in the xmlSearch to find this.  Specifically, the namespaces are throwing me.

This is what I have on the CF side, and below an except from the XML I'm working with;

<cfscript>
  xmlContent = XMLParse(trim(cfhttp.FileContent));
  xmlNode = xmlSearch(xmlContent, "//GetSalesLeadsStatisticsResponse/GetSalesLeadsStatisticsRecords/a:SalesLeadsStatisticsRecords/a:SalesLeadsStatisticsRecord");
</cfscript>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <GetSalesLeadsStatisticsResponse xmlns="http://affilinet.framework.webservices/Svc">
         <SalesLeadsStatisticsRecords xmlns:a="http://affilinet.framework.webservices/types/PublisherStatistics" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
            <a:TotalConfirmed>3.29</a:TotalConfirmed>
            <a:TotalOpen>0</a:TotalOpen>
            <a:TotalCancelled>0</a:TotalCancelled>
            <a:SalesLeadsStatisticsRecords>
               <a:SalesLeadsStatisticsRecord>
                  <a:Date>2009-06-29T00:00:53</a:Date>
                  <a:ProgramTitle>XYZRetailer</a:ProgramTitle>
                  <a:SubId>bcnx</a:SubId>
                  <a:CommissionDescription>Sale: 2 % von 164.95 EUR</a:CommissionDescription>
                  <a:Commission>3.29</a:Commission>
                  <a:Information>Note in the case of cancellation</a:Information>
                  <a:CheckDate>2009-06-30T00:00:00</a:CheckDate>
                  <a:ProgramId>0</a:ProgramId>
                  <a:TransactionStatus>Confirmed</a:TransactionStatus>
               </a:SalesLeadsStatisticsRecord>
            </a:SalesLeadsStatisticsRecords>
         </SalesLeadsStatisticsRecords>
      </GetSalesLeadsStatisticsResponse>
   </s:Body>
</s:Envelope>

Open in new window

0
Comment
Question by:Reveroom
  • 3
  • 3
6 Comments
 
LVL 27

Expert Comment

by:BigRat
ID: 24752608
Yet another XPath implementation which doesn't support XPath!

And XPath strictly speaking is NOT namespace aware.

And ColdFusion has a funny way of doing things with default namespaces.

That all said read : http://www.talkingtree.com/blog/index.cfm/2005/11/18/XmlSearchNoNameNamespace

and try puting a colon in from of those nodes with a default name space :-

xmlNode = xmlSearch(xmlContent, "//:GetSalesLeadsStatisticsResponse/:GetSalesLeadsStatisticsRecords/a:SalesLeadsStatisticsRecords/a:SalesLeadsStatisticsRecord");

0
 

Author Comment

by:Reveroom
ID: 24752631
Thanks for the reply, BigRat.

I'd actually already seen that article, and tried various alternatives as possible solutions.  Again, no dice.

Doing a straight 'copy & paste' of your code, the following error is returned:

"Prefix must resolve to a namespace: "
0
 
LVL 27

Expert Comment

by:BigRat
ID: 24753512
Nil desperandum, let's try a couple of options

1) any namespace (since exactly what namespace we are using doesn't mater in this case) :-

xmlNode = xmlSearch(xmlContent, "//*:GetSalesLeadsStatisticsResponse/*:GetSalesLeadsStatisticsRecords/a:SalesLeadsStatisticsRecords/a:SalesLeadsStatisticsRecord");

2) localname predicate

xmlNode = xmlSearch(xmlContent, "//*[local-name()='GetSalesLeadsStatisticsResponse']/:[local-name()='GetSalesLeadsStatisticsRecords']/a:SalesLeadsStatisticsRecords/a:SalesLeadsStatisticsRecord");



0
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 

Author Comment

by:Reveroom
ID: 24753612
Thanks BigRat, I appreciate you taking the time to look at this.

Still no dice however - same response as previous with both additional options :-(
0
 
LVL 27

Accepted Solution

by:
BigRat earned 500 total points
ID: 24753910
Well, it seems that the bug has either been corrected in a way which is completely different to all the system I know, or it has not been corrected but made worse.

Let us try to avoid XPath and try a DOM access.

What do you get with :-

    xmlContent.Envelope.Body.GetSalesLeadsStatisticsResponse.SalesLeadsStatisticsRecords.SalesLeadsStatisticsRecords

?
0
 

Author Comment

by:Reveroom
ID: 24754078
Thanks BigRat,

I no longer get the namespace error with that, however no results are returned.  I did a cfdump of the cfhttp response (which, in hindsight I should have done earlier), and noted that the response is actually an error.

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><s:Fault><faultcode xmlns:a="http://schemas.microsoft.com/ws/2005/05/addressing/none">a:ActionNotSupported</faultcode><faultstring xml:lang="en-US">The message with Action '' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).</faultstring></s:Fault></s:Body></s:Envelope>

I haven't actually changed anything in the Soap request since bringing it in from soapUI, so I'm even more confused than I was before now!  Clearly, this is presumably where the underlying problem is though.

I guess solving that issue is beyond the scope of this question though, so I'll go ahead and award points for giving me the guidance with the original question.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Appending query Data into array of Structure for a structure 3 43
Coldfusion : Unix Epoch Time 4 39
Fixing Old Legacy Code 1 41
SQL XML ALL Nodes Compare in function 2 37
This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question