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

Error received (sometimes) when using <cfxml> tag

Explorer ,
May 06, 2011 May 06, 2011

I have a problem when using the <cfxml> tag, its seems to error when I try and display xml code over a certain length, as it works for some of my records and not others.  Is there a known sizing limit when displaying stuff within the cfxml tag ?

Here is my code, I am un-sure as to how to progress with this issue. Any help would be much apprciated.

  <cflayout type="tab">
      <cflayoutarea title="Application XML">
         <cfoutput>
               <cftry>
                     <cfxml variable="MyXMLDoc" casesensitive="yes">
                       #getAppReqHeader.application_xml#
                     </cfxml>
                     <cfdump var="#MyXMLDoc#">
                     <cfcatch>
                      <br /><br />
                      <div style="margin-left:5px;color:gray">Error displaying xml.</div><br/>
                     </cfcatch>
               </cftry>
         </cfoutput>
        </cflayoutarea>
  </cflayout>

1.3K
Translate
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

LEGEND , May 06, 2011 May 06, 2011

Right.

So it's being truncated when it's fetched from the DB.  Nothing to do with CFXML.

Sounds like it's hitting the Long Text Buffer size (which by default is 64kB).  Increase that value (in your DSN advanced settings).

--

Adam

Translate
Participant ,
May 06, 2011 May 06, 2011

Certine carecters can through the XML off, like : & (and) for example.

You code is not posted, but you can try and use #XmlFormat()# 

http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-6e62.html

look at the link for more info ...

Translate
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
Explorer ,
May 06, 2011 May 06, 2011

Thanks for your response, I tried your suggestion but to no avail.

Here is my code now...

<cfxml variable="MyXMLDoc" casesensitive="yes">
     #XmlFormat(getBatchReqHeader.out_batch_xml)#
</cfxml>

<cfdump var="#MyXMLDoc#">

I am getting the XML from a field in the database which is of field type CLOB, I have tracked the error down to coldfusion cutting the end part of the string which is causing the error.  I am trying to display a big bit of xml... around about 65k words + .... I have a feeling that coldfusion is chopping of the end part of my string variable which makes it syntactially incorrect which is causing the error.

Now I am sure my code works because it works with smaller field lengths in the database....

Translate
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
LEGEND ,
May 06, 2011 May 06, 2011

Well: don't have a feeling that CF is truncating the string: check.  Output the string before you CFXML it.  Is it all there?

Also, you're misusing xmlFormat().  xmlFormat() is for escaping invalid characters in text values (like xmlattribute values, or xmltext values).  You don't escape the whole thing.

Also, given what you're doing, it looks like the string coming back from the DB is XML already, so you don't need to use CFXML, just use xmlParse().

It might be an idea to read through the XML section of the CF docs.

--

Adam

Translate
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
Explorer ,
May 06, 2011 May 06, 2011

Something is truncating the string as when I output it the XML is not all there... Which is why <cfxml> and <cfdump> can not parse the xml probably.

I may have given off the wrong impression, I do not want to escape the xml special charactors.  I want to show these.... Which is why I am using CFDUMP as it displays the xml in a good way.

Translate
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
LEGEND ,
May 06, 2011 May 06, 2011

Do what I asked.

Output the string BEFORE (or INSTEAD) of trying to treat it as XML.  Forget CFXML and CFDUMP, just do this:

<cfoutput>#getBatchReqHeader.out_batch_xml#</cfoutput>

Then view the source and see if the entire string is there.

There's a good chance it's being truncated when it's being fetched from the DB.

--

Adam

Translate
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
Participant ,
May 06, 2011 May 06, 2011

silly Q' if you try and dump the getBatchReqHeader.out_batch_xml as is, will all

the XML look ok ?

or do they get cut off at this stage already ?

Translate
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
Explorer ,
May 06, 2011 May 06, 2011

silly Q' if you try and dump the getBatchReqHeader.out_batch_xml as is, will all

the XML look ok ?

or do they get cut off at this stage already ?

------------------------------------------------------------------------------------

If I try and directly output it, it gets cut of at this stage, after about the 65,000 word...

Translate
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
LEGEND ,
May 06, 2011 May 06, 2011

Right.

So it's being truncated when it's fetched from the DB.  Nothing to do with CFXML.

Sounds like it's hitting the Long Text Buffer size (which by default is 64kB).  Increase that value (in your DSN advanced settings).

--

Adam

Translate
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
Explorer ,
May 06, 2011 May 06, 2011

Thanks Adam, I will give this a shot and report back...

Translate
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 ,
May 06, 2011 May 06, 2011

You can't just wrap an XML document with the XMLFormat function - that will escape all XML metacharacters. Use XMLFormat to escape metacharacters within XML text nodes and attribute values only:

<myxml someattribute="#XMLFormat(someCFVariable)#"/>

Dave Watts, CTO, Fig Leaf Software

http://www.figleaf.com/

http://training.figleaf.com/

Dave Watts, Eidolon LLC
Translate
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
Explorer ,
May 09, 2011 May 09, 2011
LATEST

Problem solved.

In the coldfusion administrator I checked the option:

    -- Enable long text retrieval (CLOB).


and all worked.

Thanks for your help guys.

Translate
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
LEGEND ,
May 06, 2011 May 06, 2011

What would also be helpful is posting the actual error.

As a rule of thumb when posting a question about code not working:

* post some code that reproduces the problem.  Not just a chunk out of the middle of your production code, but a refactored, stand-alone example demonstrating the problem.  So we can save it locally and see the problem

* any error message you get.  Not described, but copy and pasted from the screen

* a description of what you were expecting, and how what happened differs from your expectation (obviously in your case it's "I don't want the error", but it's sometimes not so clear cut as that, and people have a tendency to say "it didn't work", which by itself is meaningless).

--

Adam

Translate
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