Skip to main content
August 8, 2008
Question

XMLParse Under CF MX 6

  • August 8, 2008
  • 1 reply
  • 510 views
Is there anyone out there who has expereinec in Using XMLParse under
both CFMX 6 and CF 7 and can help me out here ?

My situation...


I did some work for a client.
As part of the work I put some 'settings' into an XML file and
arranged for them to be loaded and parsed and converted to a plain
jane structure in application.cfm.


The Client informed me when I asked in advance, that the application
was going to be run under CF 7.
I use CF 8 for development, but had full confidence that what I did
would also work under CF 7.
In fact they tried it under CF 7 (some test bed they had) and it
worked fine.


But then after I delivered the final product they installed it onto
another (production) server and suddenly we find that XMLParse comes
up with this error:
'Document Root element is missing -
Referring to the line of code that says:
<cfset settingsXMLDoc=XmlParse("./config/settings.xml", 'true')>


I assume this means they are NOT using the same version of CF that it
was earlier tested under, and I have assumed that it is CF 6.1 for the
time being.
I take the view this means that XMLParse under CF 6 was in its
rudimentary state of development and either had bugs or it just worked
differently than more recent editions.


Now this xml doc works fine under CF 7 & 8.: It has (as far as I am
aware) street Legal XML, with the following layout:
<?xml version="1.0" standalone="yes"?>
<!DOCTYPE SETTINGS [
<!ELEMENT SETTINGS (XDATA)>
<ELEMENT XDATA (#PCDATA)+>
]>
<!-- A comment -->
<SETTINGS>
<XDATA>Some data</XDATA>
</SETTINGS>
Kind of structure (in other words, it has its own embedded DTD...
Best Practice ?)
If not obvious this is just an example, the real structure is a bit
more complex

I am not in the position whereby I can tinker with the code or the XML as I do not have CF 6 nor access to the server the client is running this on. Sort of like one hand tied behind my back.

So, is anyone out there able to help me out with the right sort of XML structure that will work with CF 6 (and also hopefully also work with CF 7 & 8 ?)

Thanks,
Bryn Parrott

    This topic has been closed for replies.

    1 reply

    August 10, 2008
    I'm not sure why I bother answering my own posts however..

    the issue is resolved, and it truned out that the xmlparse function in cf 6 did not know how to open and read in an xml file. It miust first be opened and read using cffile.
    <cfset settingsXMLDoc=XmlParse("./config/settings.xml", 'true')>

    turns into:
    <cfset variables.filepath=expandpath(".\config\settings.xml")>
    <cffile action="read" file="#variables.filepath#" variable="variables.xmltxt">
    <cfset variables.settingsXMLdoc=XmlParse(variables.xmltxt,'false' )>


    Cheers
    ..BP ..