Solved

Parsing an XML file in ASP - error

Posted on 2009-04-02
3
807 Views
Last Modified: 2012-05-06
I'm trying to parse a XML file in ASP. I have provided my code and I get the following error msg:

"XML parse error: Errorcode: -1072896682 Reason: Invalid at the top level of the document. Line: 1 Filepos: 0 URL: "

I have tried 3 different XML files and all get the same error and they all have a top level.

I can't provide the XML files as the information is confidential but I can give a sample of the structure:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Root>
  <node1>
    <node1_1>text</node1_1>  
    <node1_2>text</node1_2>  
  </node1>
</Root>


Where could my problem be? Is it this line?
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

Any help appreciated.

function XML_OpenXMLFile( byRef oFSO, byRef sFilePath, bUnicode, byRef oXMLDoc, byRef sErrorMessage )
 
	dim sPhysicalPath, oTS, bHasFSO, sXML
	
	XML_OpenXMLFile = false
	
	bHasFSO = isObject( oFSO )
	
	if not bHasFSO then set oFSO = Server.CreateObject( "Scripting.FileSystemObject" )
 
	sPhysicalPath = PhysicalPath( sFilePath )
	if not oFSO.FileExists( sPhysicalPath ) then sErrorMessage = "The file """ & sFilePath & """ (" & sPhysicalPath & ") is not found!" : exit function
 
	set oTS = oFSO.OpenTextFile( sPhysicalPath, 1, false, Conditional( bUnicode, -1, 0 ) )
	sXML = oTS.ReadAll()
	oTS.Close()
	set oTS = nothing
 
	if not bHasFSO then set oFSO = nothing
	
	set oXMLDoc = Server.CreateObject("MSXML2.DOMDocument")
	oXMLDoc.async = false
	oXMLDoc.resolveExternals = false
	oXMLDoc.preserveWhiteSpace = true
	oXMLDoc.loadXML sXML
 
	if oXMLDoc.parseError.errorCode <> 0 then
		sErrorMessage = "Error parsing original XML file: " & XML_GetParseError( oXMLDoc )
		exit function
	end if
	
	XML_OpenXMLFile = true
end function

Open in new window

0
Comment
Question by:mc_101
  • 2
3 Comments
 
LVL 28

Expert Comment

by:sybe
ID: 24047825
I believe that node-names should be all lowercase. So in stead of <Root> you'd need <root>
0
 

Author Comment

by:mc_101
ID: 24047869
Doesn't change anything, still the same problem even with all nodes being lower case.
0
 
LVL 28

Accepted Solution

by:
sybe earned 500 total points
ID: 24047900
But why don't you let the oXMLDoc open the file directly? No need to use FSO. Maybe the FSO part is messing something up

<%
Set oXMLDoc = Server.CreateObject("MSXML2.DOMDocument")
oXMLDoc.load(sFilePath)
%>

Open in new window

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Load data upon clicking a button 8 48
return false must be hit after calling certain command 10 43
TSQL XML Namespaces 7 37
Can't select treeview node from iframe 2 37
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

749 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