niim
niim

Reputation: 13

SQL returning XML and need to show on Screen

I am using the following query to output XML from sql query

select * from author FOR XML RAW, ROOT ('data'), ELEMENTS XSINIL

Data is coming as expected, from CF point of view i am using this

DECLARE @XmlData XML;
                    SET @XmlData =(#preserveSingleQuotes(abovequery)#)
                    SELECT @XmlData AS Result

now when i dump it, it considers it as a string and display the xml elements in there

my Data

<data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <row>
      <authorid>5</authorid>
      <firstname>joker</firstname>
      <lastname>movie</lastname>
      <sorted>1</sorted>
      <createdon xsi:nil="true" />
      <modifiedby xsi:nil="true" />
   </row>

</data>

I want to display exactly like the above on screen, but when i either using use cfxml or xmlparse or xml any other element, it does not display in that format, it just extract the values and display it in one line

how can i fix it

Upvotes: 0

Views: 82

Answers (1)

James A Mohler
James A Mohler

Reputation: 11120

How about

<cfsavecontent variables="Result"><data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <row>
  <authorid>5</authorid>
  <firstname>joker</firstname>
  <lastname>movie</lastname>
  <sorted>1</sorted>
  <createdon xsi:nil="true" />
  <modifiedby xsi:nil="true" />
 </row>

</data></cfsavecontent>

<pre><cfoutput>#EncodeForHTML(Result)#</cfoutput></pre>

See: https://cffiddle.org/app/file?filepath=466fa116-bd65-46a8-a41d-0c84bc99169d/b7082ec0-8f27-43bf-9216-60a2034bdcab/90c4ab0f-d83c-400a-a8e2-1874da28b884.cfm

Upvotes: 3

Related Questions