Link to home
Start Free TrialLog in
Avatar of ptslv
ptslvFlag for United States of America

asked on

Urgent - Passed file not being read for XML parsing

This is a follow-up to my previous question concerning parsing XML in ColdFusion and placing the data into an Access database.

I am able to grab an XML file, parse it and submit the data.  I am now trying to get it to where the user can browse for the XML file to work with.  I am able to browse for the file and upload it to where it needs to be.  But when I pass the file to the main page, I get the following error:  Object Required.  None of the form fields are being found in the file.  How can I fix it so that the passed file is being read?


Here's the code:

//Browse for the file and upload it
<html><head>      <title>Untitled</title></head>
<body>
<cfform name="getXMLFile" action="uploadXML.cfm" method="Post" enctype="multipart/form-data">
<p>&nbsp;
<table width="500" align="center" bgcolor="#C8DFCE" border="3" cellpadding="3" cellspacing="3">
      <tr>
            <td height="200"><P align="center"><b>Select the file or enter the path of the XML file you wish to work with.</b><br>
            <p>XML FILE:  <input type="File" name="MyFile" size="75"><br>
            <br>
            <p align="center"><input type="Submit" value="NEXT >>"></td></tr>
</table>
</cfform></body></html>

//Upload the file:
<html><head><title>Untitled</title></head>
<body>
<CFFile accept="text/xml" action="Upload" filefield="MyFile" attributes="ReadOnly"    destination="C:\inetpub\wwwroot\MyApp\TempXMLFiles\" nameconflict="ERROR">
 <cfset yourFilename ="#File.ClientFile#">
       <cfoutput><CFLOCATION URL="./LoadXML3.cfm?yourFilename=#yourFilename#" addtoken="no"></cfoutput>
</body></html>


//Parsing the file:

<html>
<head>
<script type="text/javascript" for="window" event="onload">
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
xmlDoc.async="false"

xmlDoc.load("document.LoadXML3.yourFile.value")

DocumentName.innerText=xmlDoc.getElementsByTagName("DocumentName").item(0).text;
DocumentType.innerText=xmlDoc.getElementsByTagName("DocumentType").item(0).text;
TransactionType.innerText=xmlDoc.getElementsByTagName("TransactionType").item(0).text;
DocNum.innerText=xmlDoc.getElementsByTagName("DocNum").item(0).text;
document.LoadXML3.DocumentName.value = xmlDoc.getElementsByTagName("DocumentName").item(0).text;
document.LoadXML3.DocumentType.value = xmlDoc.getElementsByTagName("DocumentType").item(0).text;
document.LoadXML3.TransactionType.value = xmlDoc.getElementsByTagName("TransactionType").item(0).text;
document.LoadXML3.DocNum.value = xmlDoc.getElementsByTagName("DocNum").item(0).text;
</script>
<script>
<!--
function IsValid(doc)
{
      alert("Document Name is:  " + window.document.LoadXML3.DocumentName.value + "/n" + "Document Type is: " + window.document.LoadXML3.DocumentType.value);
alert("Document Type is: " + window.document.LoadXML3.DocumentType.value);
      return true;
}
//-->
</script>
</head>
<body bgcolor="#c6dfdb">
<form name="LoadXML3" action="./loadData.cfm" method="post">

<cfif isDefined("URL.yourFilename")>
      <cfset yourFile = #URL.yourFilename#>
<cfelse>
      <cfset yourFile = "">
</cfif>

<cfoutput><input type="hidden" name="yourFile" value="#yourFile#"></cfoutput>

<h1 align="center"><cfoutput>#yourFile# E Data</cfoutput></h1>

<table align="center" width="500" border="5" bgcolor="#D9DDC1">
    <tr>
     <td><b>DocumentName: </b><span id="DocumentName"></span><br>
                       <b>DocumentType: </b><span id="DocumentType"></span><br>
                       <b>TransactionType: </b><span id="TransactionType"></span><br>
                       <b>DocNum: </b><span id="DocNum"></span><br><br>
</td></tr>
</table>

<input type="Hidden" name="DocumentName" value="">
<input type="Hidden" name="DocumentType" value="">
<input type="Hidden" name="TransactionType" value="">
<input type="Hidden" name="DocNum" value="">

<input type="Button" name="but" value="SHOW HIDDEN VALUE" onclick="javascript: alert(document.LoadXML3.DocumentName.value);">
<input type="button" name="submit" value="Submit" onClick="document.LoadXML3.submit()" >
</form>
</body>
</html>
ASKER CERTIFIED SOLUTION
Avatar of reggi635
reggi635

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tacobell777
Tacobell777

Question: why do you use javascript? Why not use createObject in cf? Make it server-side instead of client side...
Avatar of ptslv

ASKER

Tacobell77 - I am using javascript because that is the only example parsing XML with CF that I have found.

REGGI, this is the error that I get:

An error occurred while evaluating the expression: #variables.yourFileName#
Error near line 9, column 25.
--------------------------------------------------------------------------------
Error resolving parameter VARIABLES.YOURFILENAME
The specified variable name cannot be found. This problem is very likely due to the fact that you have misspelled the variable name.
The error occurred while processing an element with a general identifier of (#variables.yourFileName#), occupying document position (9:24) to (9:47).

ptslv
I would agree with Tacobell that parsing of XML from ColdFusion will be much more easier. This is the way I do my XML parsing. Just in case if you change your mind to parse the XML file  by using the "Cool" functions of ColdFusion please let us know.

Anyways to get back to your issue if the name of the URL parameter after the XML file is uploaded is yourFileName then you shouldn't get the Error.

Check in the list of URL parameters in the Coldfusion debugging information as to what's the name of the parameter which holds the file name. Once you get that add it here

xmlDoc.load("<cfoutput>#URL.yourFileName#</cfoutput>");

Thanks
REGGI
Avatar of ptslv

ASKER

I would love to make this work server-side.  I just don't know how to set it up that way.   Can you show me how to do the parsing server-side?

ptslv
Avatar of ptslv

ASKER

I was finally able to get a copy of the CF 4.5 documentation.  I am going to read up on doing this server-side.  Meanwhile I will try to get it working thru javascript.

ptslv
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ptslv

ASKER

I had to get the disk back so I could re-install the documentation.  Don't ask - long story!  Unfortunately, I work for a contractor with limited funding and do not have the latest and greatest software to work with.  So I need to make do with what I have.

I just need to get something working to demo what I am doing.  Right now, I can't get it to work thru javascript unless I hardcode the file.  That will not do with 30+- coming in each day.  I still am not able to get the file passed.  It's there in the URL, and comes up in the <cfoutput> to the page, but it's not getting to the load().  Any other suggestions to get it working with javascript while I muddle thru building for server-side?

ptslv
I guess the XML template that you are uploading has the same structure everytime else you will get
a javascript error because it would not find the node. If the structure changes then the Error would NOT be on this line.

xmlDoc.load("<cfoutput>#URL.yourFileName#</cfoutput>");

it would be somewhere here bcos it would not find the getElementsByTagName

DocumentName.innerText=xmlDoc.getElementsByTagName("DocumentName").item(0).text;
DocumentType.innerText=xmlDoc.getElementsByTagName("DocumentType").item(0).text;
TransactionType.innerText=xmlDoc.getElementsByTagName("TransactionType").item(0).text;
DocNum.innerText=xmlDoc.getElementsByTagName("DocNum").item(0).text;

The point is XML uploaded needs to be very consistent WRT nodes.

REGGI
Avatar of ptslv

ASKER

REGGI -

Fixed the javascript error.

Changed your line :  <cfoutput>xmlDoc.load("#variables.yourFileName#");</cfoutput>

to read:  xmlDoc.load(<cfoutput>"#yourFileName#"</cfoutput>);

ptslv
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ptslv

ASKER

I split the points because I got some good info from Tacobel777 also.  Parsing using the server-side won't help me because I'm using 4.5 and I get error messages that ColdFusion functions don't exist when I try to do the server side.  Thanks for all the help.  I appreciate it!

ptslv