John Egbert
John Egbert

Reputation: 69

Coldfusion XML output injecting doc header info

I've been looking through things for the last number of hours, I can't figure this one out! Ultimately, I have some xml data that is coming in from a HTTPheader:

<cfset xmlPOST = GetHTTPRequestData().content>
<cfset xmlDOM = XmlParse(xmlPOST)>
<cfset BCsetup = xmlDOM.cXML.Request.PunchOutSetupRequest.BuyerCookie>

I'm attempting to get the BuyerCookie, use it, and place it into a new xml document. If I cfoutput BCsetup right now, it gives me the right value (lets say 12345).

The second I place it as an output into the XML, it throws <xml version="1.0" encoding="UTF-8"?><BuyerCookie>12345</BuyerCookie> instead of 12345.

I've tried everything from toString() to cfsavecontent to try to resave the variable down and straight text, etc etc etc. I can't for the life of me figure out how to make this work.

UPDATED: Here's the code that is performing as described above:

<cfset BCsetup = xmlDOM.cXML.Request.PunchOutSetupRequest.BuyerCookie> 


<!DOCTYPE cXML SYSTEM "http://xml.cxml.org/schemas/cXML/1.2.020/cXML.dtd">
<cXML payloadID="2009-11-02T13:27:53+10:00" timestamp="2009-11-02T13:27:53+10:00">
  <Response>
    <Status code="200" text="OK"/>
    <PunchOutSetupResponse>
      <StartPage>
        <URL>https://mysite.com/testpost.cfm?BuyerCookie=<cfoutput>#BCsetup#</cfoutput></URL>
      </StartPage>
    </PunchOutSetupResponse>
  </Response>
</cXML>

Upvotes: 2

Views: 218

Answers (2)

Matt Busche
Matt Busche

Reputation: 14333

<cfset BCsetup = xmlDOM.cXML.Request.PunchOutSetupRequest.BuyerCookie> 

pulls in the entire XML element and not a specific value. If you change that to pull in xmlText it should fix your issue

<cfset BCsetup = xmlDOM.cXML.Request.PunchOutSetupRequest.BuyerCookie.xmlText>

I would recommend running <cfdump var="#BCSetup#" abort> after you set it to make sure you're getting the value you want.

Upvotes: 1

snake
snake

Reputation: 752

Your code is getting the xmldom element not just its value, justadd .xmltext to the end to get the text only and not the element.

Upvotes: 0

Related Questions