ptslv
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></h ead>
<body>
<cfform name="getXMLFile" action="uploadXML.cfm" method="Post" enctype="multipart/form-da ta">
<p>
<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>Untitle d</title>< /head>
<body>
<CFFile accept="text/xml" action="Upload" filefield="MyFile" attributes="ReadOnly" destination="C:\inetpub\ww wroot\MyAp p\TempXMLF iles\" nameconflict="ERROR">
<cfset yourFilename ="#File.ClientFile#">
<cfoutput><CFLOCATION URL="./LoadXML3.cfm?yourFi lename=#yo urFilename #" addtoken="no"></cfoutput>
</body></html>
//Parsing the file:
<html>
<head>
<script type="text/javascript" for="window" event="onload">
var xmlDoc = new ActiveXObject("Microsoft.X MLDOM")
xmlDoc.async="false"
xmlDoc.load("document.Load XML3.yourF ile.value" )
DocumentName.innerText=xml Doc.getEle mentsByTag Name("Docu mentName") .item(0).t ext;
DocumentType.innerText=xml Doc.getEle mentsByTag Name("Docu mentType") .item(0).t ext;
TransactionType.innerText= xmlDoc.get ElementsBy TagName("T ransaction Type").ite m(0).text;
DocNum.innerText=xmlDoc.ge tElementsB yTagName(" DocNum").i tem(0).tex t;
document.LoadXML3.Document Name.value = xmlDoc.getElementsByTagNam e("Documen tName").it em(0).text ;
document.LoadXML3.Document Type.value = xmlDoc.getElementsByTagNam e("Documen tType").it em(0).text ;
document.LoadXML3.Transact ionType.va lue = xmlDoc.getElementsByTagNam e("Transac tionType") .item(0).t ext;
document.LoadXML3.DocNum.v alue = xmlDoc.getElementsByTagNam e("DocNum" ).item(0). text;
</script>
<script>
<!--
function IsValid(doc)
{
alert("Document Name is: " + window.document.LoadXML3.D ocumentNam e.value + "/n" + "Document Type is: " + window.document.LoadXML3.D ocumentTyp e.value);
alert("Document Type is: " + window.document.LoadXML3.D ocumentTyp e.value);
return true;
}
//-->
</script>
</head>
<body bgcolor="#c6dfdb">
<form name="LoadXML3" action="./loadData.cfm" method="post">
<cfif isDefined("URL.yourFilenam e")>
<cfset yourFile = #URL.yourFilename#>
<cfelse>
<cfset yourFile = "">
</cfif>
<cfoutput><input type="hidden" name="yourFile" value="#yourFile#"></cfout put>
<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"></spa n><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.Do cumentName .value);">
<input type="button" name="submit" value="Submit" onClick="document.LoadXML3 .submit()" >
</form>
</body>
</html>
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></h
<body>
<cfform name="getXMLFile" action="uploadXML.cfm" method="Post" enctype="multipart/form-da
<p>
<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>Untitle
<body>
<CFFile accept="text/xml" action="Upload" filefield="MyFile" attributes="ReadOnly" destination="C:\inetpub\ww
<cfset yourFilename ="#File.ClientFile#">
<cfoutput><CFLOCATION URL="./LoadXML3.cfm?yourFi
</body></html>
//Parsing the file:
<html>
<head>
<script type="text/javascript" for="window" event="onload">
var xmlDoc = new ActiveXObject("Microsoft.X
xmlDoc.async="false"
xmlDoc.load("document.Load
DocumentName.innerText=xml
DocumentType.innerText=xml
TransactionType.innerText=
DocNum.innerText=xmlDoc.ge
document.LoadXML3.Document
document.LoadXML3.Document
document.LoadXML3.Transact
document.LoadXML3.DocNum.v
</script>
<script>
<!--
function IsValid(doc)
{
alert("Document Name is: " + window.document.LoadXML3.D
alert("Document Type is: " + window.document.LoadXML3.D
return true;
}
//-->
</script>
</head>
<body bgcolor="#c6dfdb">
<form name="LoadXML3" action="./loadData.cfm" method="post">
<cfif isDefined("URL.yourFilenam
<cfset yourFile = #URL.yourFilename#>
<cfelse>
<cfset yourFile = "">
</cfif>
<cfoutput><input type="hidden" name="yourFile" value="#yourFile#"></cfout
<h1 align="center"><cfoutput>#
<table align="center" width="500" border="5" bgcolor="#D9DDC1">
<tr>
<td><b>DocumentName: </b><span id="DocumentName"></span><
<b>DocumentType: </b><span id="DocumentType"></span><
<b>TransactionType: </b><span id="TransactionType"></spa
<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.Do
<input type="button" name="submit" value="Submit" onClick="document.LoadXML3
</form>
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Question: why do you use javascript? Why not use createObject in cf? Make it server-side instead of client side...
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
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#)
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>#UR L.yourFile Name#</cfo utput>");
Thanks
REGGI
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>#UR
Thanks
REGGI
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
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
ptslv
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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 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>#UR L.yourFile Name#</cfo utput>");
it would be somewhere here bcos it would not find the getElementsByTagName
DocumentName.innerText=xml Doc.getEle mentsByTag Name("Docu mentName") .item(0).t ext;
DocumentType.innerText=xml Doc.getEle mentsByTag Name("Docu mentType") .item(0).t ext;
TransactionType.innerText= xmlDoc.get ElementsBy TagName("T ransaction Type").ite m(0).text;
DocNum.innerText=xmlDoc.ge tElementsB yTagName(" DocNum").i tem(0).tex t;
The point is XML uploaded needs to be very consistent WRT nodes.
REGGI
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>#UR
it would be somewhere here bcos it would not find the getElementsByTagName
DocumentName.innerText=xml
DocumentType.innerText=xml
TransactionType.innerText=
DocNum.innerText=xmlDoc.ge
The point is XML uploaded needs to be very consistent WRT nodes.
REGGI
ASKER
REGGI -
Fixed the javascript error.
Changed your line : <cfoutput>xmlDoc.load("#va riables.yo urFileName #");</cfou tput>
to read: xmlDoc.load(<cfoutput>"#yo urFileName #"</cfoutp ut>);
ptslv
Fixed the javascript error.
Changed your line : <cfoutput>xmlDoc.load("#va
to read: xmlDoc.load(<cfoutput>"#yo
ptslv
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
ptslv