Renshi
Renshi

Reputation: 77

ColdFusion 11 xml markup is included when referencing node value

I'm trying to get the value of some xml nodes but for some reason it is returning the markup around the value also. Any idea why and how I can get the value only? Below is an example of my issue.

Here is the xml dump XML cfdump

Then I am referencing the XML like so.

<cfset ResponseXML = #xmlparse(getOrders)#>
<cfset OrderNodes = ResponseXML.list.elements.order>
<cfoutput>#OrderNodes.orderDate#</cfoutput>

Then when I see it on the screen it looks correct and it gives me the date from the xml on the screen. If I try to insert it into a date type field in the database it tells me it can't convert to string so I start looking at the view source and it is actually returning this

 <?xml version="1.0" encoding="UTF-8"?><orderDate>2017-02-21T20:48:11.000Z</orderDate>

So why is it returning xml markup when I reference the node value like that? How can I just get the value and not that extra markup?

Thank in advance.

Upvotes: 2

Views: 47

Answers (1)

Miguel-F
Miguel-F

Reputation: 13548

As your dump shows, you need to reference the data using the XmlText element of the parsed structure.

<cfoutput>#OrderNodes.orderDate.XmlText#</cfoutput>

Upvotes: 2

Related Questions