Solved

Urgent - Passed file not being read for XML parsing

Posted on 2004-09-27
13
274 Views
Last Modified: 2013-12-24
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
Comment
Question by:ptslv
  • 6
  • 5
  • 2
13 Comments
 
LVL 4

Accepted Solution

by:
reggi635 earned 350 total points
ID: 12164604
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
 
LVL 17

Expert Comment

by:Tacobell777
ID: 12165351
Question: why do you use javascript? Why not use createObject in cf? Make it server-side instead of client side...
0
 

Author Comment

by:ptslv
ID: 12179766
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
 
LVL 4

Expert Comment

by:reggi635
ID: 12180173
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
 

Author Comment

by:ptslv
ID: 12180233
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
 

Author Comment

by:ptslv
ID: 12180561
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
Network it in WD Red

There's an industry-leading WD Red drive for every compatible NAS system to help fulfill your data storage needs. With drives up to 8TB, WD Red offers a wide array of solutions for customers looking to build the biggest, best-performing NAS storage solution.  

 
LVL 4

Assisted Solution

by:reggi635
reggi635 earned 350 total points
ID: 12180901
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
 

Author Comment

by:ptslv
ID: 12181231
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
 
LVL 4

Expert Comment

by:reggi635
ID: 12181594
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
 

Author Comment

by:ptslv
ID: 12182292
REGGI -

Fixed the javascript error.

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

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

ptslv
0
 
LVL 4

Assisted Solution

by:reggi635
reggi635 earned 350 total points
ID: 12182572
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
 
LVL 17

Assisted Solution

by:Tacobell777
Tacobell777 earned 150 total points
ID: 12183501
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
 

Author Comment

by:ptslv
ID: 12191009
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

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now