naveen
naveen

Reputation: 11

Encoding of data from XML file and ASP.NET textbox

I'm trying to compare a string obtained through a textbox and a string read from an XML file. The XML file is as given below.

<?xml version="1.0" encoding = "UTF-8" ?>
<cars>
   <car>
       <name>
           Honda
       </name>
   </car>
</cars>

The trouble is that when I compare the text "Honda" read from the XML file and the text obtained from the textbox, the comparison fails. I checked the length of both texts. The length of the text from the textbox is correctly shown while that from the XML file is 4 times larger. I'm wondering whether this has got something to do with the encoding of the texts. I'm not sure how we can make both text in the same format.

Any help would be great!

Thanks,

Upvotes: 1

Views: 743

Answers (1)

BrokenGlass
BrokenGlass

Reputation: 160852

With the XML that you pasted the value of name looks like \n Honda \n to me - remove all the white space and newlines from within your <name> tag and they should be identical.

Remember that all characters that are not markup will be passed to the application when you parse a node - in this case this includes the white space characters that are difficult to see and weed out sometimes, but they are there.

Upvotes: 2

Related Questions