Chinese problem when Castor generates XML files

xiaoxiao2021-03-06  40

Today you need to expand the function of an old system, and the old system uses CASTOR to operate XML, and the corresponding JavaBean is available. I want to use and found JavaBeab: DeviceTable provides a ready public void marshal (Writer out) throws ValidationException, MarshalException {} such a function, then the code to easily kneaded, xmlreader = new InputStreamReader (new FileInputStream (xmlfilename)); devicetable = (DeviceTable) Unmarshaller.unmarshal (DeviceTable.class, xmlreader); and xmlwriter = new OutputStreamWriter (new FileOutputStream (xmlfilename)); devicetable.marshal (xmlwriter); Chinese but found a property wherein the value of the (labelFont = "Founder Wei Yu Simplified, ") This property is correct, so I doubt the DeviceTable.Marshal () method, by anti-compilation, oh: public void marshal (Writer out) throws validationException, Marshalexception {Marshaller.Marshal (this, out);} It turned out to have such a province, Castor's Marshaller.Marshal () default "UTF-8", then he is coming,

xmlreader = new InputStreamReader (new FileInputStream (xmlfilename), "gb2312"); devicetable = (DeviceTable) Unmarshaller.unmarshal (DeviceTable.class, xmlreader); ...... xmlwriter = new OutputStreamWriter (new FileOutputStream (xmlfilename), " GB2312 "); Marshaller Marshaller = New Marshaller (XMLWRITER); Marshaller.setencoding (" GB2312 "); // Key Marshaller.Marshal (DeviceTable);

Oh, ok!

转载请注明原文地址:https://www.9cbs.com/read-59877.html

New Post(0)