We help IT Professionals succeed at work.

VBScript: Ignoring special characters on XML input?

Cerixus
Cerixus asked
on
1,768 Views
Last Modified: 2012-06-27
I'm using the attached code to read an XML file.  The problem is, I'm encountering a lot of special characters such as "é" and even "&" which causes it to fail with one of the following errors:

  Error #-1072896760 (Line: 41) - An invalid character was found in text content.
  Error #-1072896749 (Line: 41) - Whitespace is not allowed at this location.

The XML files are coming from multiple export sources, so I'd really like to handle these on the import.  Any suggestions?
set xmlDoc = CreateObject("Msxml2.DOMDocument") 
xmlDoc.validateOnParse="true"
xmlDoc.load(filename) 
if xmlDoc.parseError.errorCode = 0 then
	(read elements and do stuff)
else
	set logFS = CreateObject("Scripting.FileSystemObject")
	set objLogFile = logFS.OpenTextFile(logfile, 8, True)
	objLogFile.writeline(vbtab & "Error #" & xmlDoc.parseError.errorCode & " (Line: " & xmlDoc.parseError.line & ", " & xmlDoc.parseError.linepos & ") - " & xmlDoc.parseError.reason)
	objLogFile.Close
	set logFS = nothing
	set objLogFile = nothing
end if
set fs=nothing

Open in new window

Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
Hi, can you show us the function you use as line 41 that is producing those errors?

Rob.

Author

Commented:
Line 41 is the line in the XML file with the invalid character ("&", "é", etc)

Author

Commented:
Basically, xmlDoc.load(filename)  is generating an error when it tries to load an XML file that contains a non-standard character.  What I need to know is if there is some other character set I can use, some switch that will ignore non-standard characters, or some other way to fix this problem upon reading the file.
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.