Parsing an XML file in ASP - error

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"?>

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()
	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

Who is Participating?
sybeConnect With a Mentor Commented:
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")

Open in new window

I believe that node-names should be all lowercase. So in stead of <Root> you'd need <root>
mc_101Author Commented:
Doesn't change anything, still the same problem even with all nodes being lower case.
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.

All Courses

From novice to tech pro — start learning today.