【发布时间】:2013-04-10 04:23:57
【问题描述】:
我正在尝试解析一个 Xml 文件,其中一个 pf 标记元素如下
126.5�105�15-4�45�-16MnCr5-1
当我尝试使用 jaxb 解析并读取 xml 时,内容被更改为如下所示
126.5 �— 105 �— 15-4�—45°-16MnCr5-1
我不知道为什么我也检查了 unicode 格式,默认情况下它采用的是 cp1252 格式而不是 UTF-8 格式,即使我在 xml kinldy 帮助中指定了这里是读取传递的 xml 属性的方法xml文件和jaxbclass映射
protected T readXml(File xmlFile, Class<?> clazz) throws JAXBException, IOException, XMLStreamException {
JAXBContext jaxbContext = null;
Unmarshaller unmarshaller = null;
jaxbContext = JAXBContext.newInstance(clazz);
unmarshaller = jaxbContext.createUnmarshaller();
XMLInputFactory factory = XMLInputFactory.newInstance();
XMLStreamReader streamReader = null;
streamReader = factory.createXMLStreamReader(new FileReader(xmlFile));
return (T) unmarshaller.unmarshal(streamReader);
}
【问题讨论】:
标签: xml-parsing jaxb saxparser