• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 286
  • Last Modified:

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>
0
ptslv
Asked:
ptslv
  • 6
  • 5
  • 2
4 Solutions
 
reggi635Commented:
That's a javascript error. I guess its unable to load the XML in this line:

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


delete the above line to the top of you template and add this in LoadXML3.cfm  

<cfparam name="variables.yourFileName" default="">

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

Let me know.
REGGI


0
 
Tacobell777Commented:
Question: why do you use javascript? Why not use createObject in cf? Make it server-side instead of client side...
0
 
ptslvAuthor Commented:
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
0
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

 
reggi635Commented:
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
0
 
ptslvAuthor Commented:
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
0
 
ptslvAuthor Commented:
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
0
 
reggi635Commented:
After getting all the way here you got a copy of coldFusion 4.5. ;-) Just kidding..

Thats not going to help you atall for the parsing the XML .
See this:
http://livedocs.macromedia.com/coldfusion/6.1/htmldocs/tags-b21.htm#wp2497244
The current version of ColdFusion MX has lot more functionality that can serve your puspose.

If intersted in server side parsing this would help you

<!--- Read the XML File --->
<cfhttp url="http://servername/dirname/filename.xml" method="GET" resolveUrl="false">
<!--- Create a XML Object ---->
<cfset myXMLDoc = XMLParse(cfhttp.filecontent)>
<!--- Display the structure of the XML --->
<cfdump var="#myXMLDoc#">

Once you can get here it's as simple as looping over the structure and displaying the nodes OR
simply refrencing the node of the required data.
LIKE
myXML.XMLRoot.XMLChildren[ 1 ].XMLAttributes["What ever param is there"]

The above line can vary depending on how you XML structure looks like. This is just an Example.
REGGI


0
 
ptslvAuthor Commented:
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
0
 
reggi635Commented:
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
0
 
ptslvAuthor Commented:
REGGI -

Fixed the javascript error.

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

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

ptslv
0
 
reggi635Commented:
Make sure add the scope variable to it. Makes it faster.

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

and a
<cfparam name="URL.yourFileName" default="">
at the top.

REGGI
0
 
Tacobell777Commented:
with createobject the syntax will be almost the same as the one you got for js now.... just do a search in google for
"createobject Microsoft.XMLDOM"
0
 
ptslvAuthor Commented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 6
  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now