Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange character in the begining xml file

I´m trying to parse one xml but it shows a error, if I put a system.out.println to the String i see it.

before

<?xml version="1.0" 

after

?<?xml version="1.0"

I´m changing the charset to UTF-8 but didn´t works, so, what should I do?

like image 710
Diego Macario Avatar asked Oct 18 '25 14:10

Diego Macario


1 Answers

You have a UTF-8 string (which is why Notepad++ is recognizing it as such), but UTF-8 doesn't require a BOM. Some programs produce it; some don't. This leads to occasional confusion when reading files - some readers (like the one you're using in your Java code) don't recognize and ignore it. I'd recommend something like the accepted answer to this question or this one for removing it. Make sure you implement a check to determine if the first 3 bytes actually are a BOM before removing them from all incoming strings.

like image 139
Josh Avatar answered Oct 20 '25 03:10

Josh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!