0

I have written a code for generating XML with UTF-8 encoding.I always validate the XML with XSD file. In the same code i need UTF-16 encoding. Because one of my XSD file is of UTF-16 encoding. But in my existing code it is not accepted. it gives following error.

FAILED: Fatal error: Document labelled UTF-16 but has UTF-8 content at filepath/standard.xsd:1.

and at line 1 of XSD this tag is defined <?xml version="1.0" encoding="utf-16"?>

How can i validate it with utf-8 encoding?

Is there any way to change UTF-16 to UTF-8 encoding. Thanks in advance.

Sumit Munot
  • 3,748
  • 1
  • 32
  • 51

1 Answers1

0

You can change the encoding from utf16 to utf-8 with Iconv

Call iconv from Ruby 1.8.7 through system to convert a file from utf-16 to utf-8

When you write the new file you can replace the first line with a new header like

<?xml version="1.0" encoding="utf-8" ?>

Ruby - Open file, find and replace multiple lines

If you need it in the other way then change the endoding in the function.

Community
  • 1
  • 1
René Höhle
  • 26,716
  • 22
  • 73
  • 82