Sharath Vollala
Sharath Vollala

Reputation: 115

Getting parsing error while reading XML file because of unescaped characters

I have an XML file which contains some escape characters in it. When I am trying to read that using xpathdocument class in VB I am getting parsing as "The '<' character, hexadecimal value 0x3C, cannot be included in a name. Line #, position #."

How to replace that escape characters before passing that xml file to xpathdocument? The xml file is:

      <classes>
      <class>Class&</class>
      <name>.net></name>
      </classes>  

Upvotes: 0

Views: 884

Answers (2)

Yosem
Yosem

Reputation: 4765

I agree, the best solution is to get a proper file, however, there are times when that can be difficult.

I had a customer where I had to go through their XML file first as a text file, line by line, and do a replace on escape characters. Only then did I load it into my XMLdocument. It worked. This is not ideal and can lead to other problems if that XML file is large or will change a lot. (Also if someone comes along behind you needing to maintain your code. But it might work.) Hope this helps, but remember, if you do it this way you are risking run-time errors later if you haven't accounted for all the scenarios you will encounter in the xml file.

Upvotes: 0

Brenda Bell
Brenda Bell

Reputation: 1139

It's impossible to answer your question without knowing the complete context. It could be that the < is valid, but something appearing before the < is the root cause of the issue.

The best course of action would be to go back to wherever you got the XML file and request a syntactically correct replacement.

W3C has an XML Validator that's very useful for finding XML errors.

Upvotes: 1

Related Questions