“Content is not allowed in prolog” when parsing perfectly valid XML on GAE

后端 未结 13 2125
抹茶落季
抹茶落季 2020-11-27 15:20

I\'ve been beating my head against this absolutely infuriating bug for the last 48 hours, so I thought I\'d finally throw in the towel and try asking here before I throw my

13条回答
  •  日久生厌
    2020-11-27 16:04

    I was facing the same issue. In my case XML files were generated from c# program and feeded into AS400 for further processing. After some analysis identified that I was using UTF8 encoding while generating XML files whereas javac(in AS400) uses "UTF8 without BOM". So, had to write extra code similar to mentioned below:

    //create encoding with no BOM
    Encoding outputEnc = new UTF8Encoding(false); 
    //open file with encoding
    TextWriter file = new StreamWriter(filePath, false, outputEnc);           
    
    file.Write(doc.InnerXml);
    file.Flush();
    file.Close(); // save and close it
    

提交回复
热议问题