0

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>  
halfer
  • 19,824
  • 17
  • 99
  • 186
Sharath Vollala
  • 107
  • 1
  • 3
  • 16
  • Whatever made this "xml" file should not have put them in. It's not valid xml. – Don Roby Sep 16 '12 at 18:23
  • xml file is created manually and given to my application where i will read that..so there is scope to enter escape characters in xml file..file is writen using xmlwriter or xmldocument – Sharath Vollala Sep 16 '12 at 18:26

2 Answers2

1

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.

Brenda Bell
  • 1,139
  • 8
  • 10
  • sorry i didnt get what u told – Sharath Vollala Sep 16 '12 at 18:26
  • Your example is the perfect illustration of what I was trying to explain. The problem has nothing to do with any < character. The first issue is the unencoded `&` following `Class`; the second problem is the unencoded `>` that follows `.net`. The best solution is still to go to the source to obtain a valid XML file. – Brenda Bell Sep 16 '12 at 22:40
0

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.

Yosem
  • 4,685
  • 3
  • 22
  • 29