I am trying read_xml() on an xml-format config file, which starts like this:

<?xml version=”1.0” encoding=”UTF-16”> …..

This file is well-formed and verified by “XML Copy Writer”, it can also be open by IE or Filefox with no problem.

 

I am using this code snippet to parse this file:

 

try{

                read_xml<wptree>(xmlfile,pt);

} catch(xml_parser-error e)

{

                e.what();

}

 

and it throws an exception saying “expected <”.

 

By looking into the code I found that,  this caused by the fact that the xmlfile starts with a Unicode Byte Order Mark (BOM)-0xFFFE .

“fffe 3c00 3f00 7800 ……”

However, read_xml() cannot handle this BOM byte and throws. It’s easy to fix it by simply discard the BOM byte, but I wonder whether there is already a flag to enable/disable this that I am unaware of.

 

Can anyone help to clarify?

Thanks,

tom