castor xml转javabean 异常“Illegal Text data found as child of” castorxml转javabeanxml映射pojojava异常 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我都是用xstream 转换 ,需要的话可以给你个例子。 我没用过castor xml。不过看到错误提示,说明肯定是配置文件的问题。rg.xml.sax.SAXException: Illegal Text data found as child of: objects我猜<objects>节点下面是不是还要有子节点。 用xstream的话,好像要自己实现converter的。 import java.io.File;import java.io.FileInputStream;import java.util.ArrayList;import java.util.List;import org.apache.commons.io.FileUtils;import com.cmmb.compress.ZipUtils;import com.thoughtworks.xstream.XStream;public class XmlStream { public static void main(String[] args) { Person person=new Person("马","10.13",26); Person person1=new Person("马","10.13",26); List l=new ArrayList(); l.add(person); l.add(person1); Persons p=new Persons("dddd",l); try { XStream s=new XStream(); s.alias("Persons", Persons.class); s.alias("Person", Person.class); //s.addImplicitCollection(Persons.class,"perList"); //s.useAttributeFor(Person.class,"name"); //String xml=s.toXML(p); File f=new File("c:/ddd.xml"); FileInputStream in=new FileInputStream(f); Persons pp=(Persons)s.fromXML(in); System.out.println(pp.getNumber()); String str =((Person)pp.getPerList().get(1)).getName(); System.out.println(str); byte[] bytes=str.getBytes(); String res=""; if(ZipUtils.isUtf8(bytes)){ String tmpISO=new String(bytes,"ISO-8859-1"); res = new String(str.getBytes("ISO-8859-1"),"UTF-8"); System.out.println(1); }else{ String tmpISO=new String(bytes,"ISO-8859-1"); res = new String(str.getBytes("GB2312"),"UTF-8"); System.out.println(2); } System.out.println(res);// File f=new File("c:/ddd.xml");// if(!f.exists()){// f.createNewFile();// }else{// // //FileUtils.deleteDirectory(f); //// }// FileOutputStream out=new FileOutputStream(f);// out.write(xml.getBytes());// out.close(); } catch (Exception e) { e.printStackTrace(); System.out.println(e.getMessage()); } }} 只需要自己写类就成了 ,很方便 ,他利用的dom解析的 ,文件大的时候性能会不怎么好,小文件还是可以的。 没有试,最后还是用Log4j解析了 Spring整合Hibernate,出现空指针异常!!! 求救。用ssh,在前台传list后台收到值为空值! 高分求助一问题 asp.net如何实现软键盘? 开发 ejb大家用什么工具呀 jboss3.2.2开发Class重新部署后服务器结果返回没有改变问题 jbulider+weblogic 联姻问题。在线等。 工作流中,数据参数怎么传递?怎么样调用应用接口? Java WSDK是什么?和Axis有关系吗? 奇怪的错误???在线等 JSP中是如何禁止后退键的?采用struts开发,mapping.findForward转向后,如何才能禁止后退键? 字符相关(考考菜鸟)
不过看到错误提示,说明肯定是配置文件的问题。
rg.xml.sax.SAXException: Illegal Text data found as child of: objects
我猜<objects>节点下面是不是还要有子节点。
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.List;import org.apache.commons.io.FileUtils;import com.cmmb.compress.ZipUtils;
import com.thoughtworks.xstream.XStream;
public class XmlStream {
public static void main(String[] args) {
Person person=new Person("马","10.13",26);
Person person1=new Person("马","10.13",26);
List l=new ArrayList();
l.add(person);
l.add(person1);
Persons p=new Persons("dddd",l);
try {
XStream s=new XStream();
s.alias("Persons", Persons.class);
s.alias("Person", Person.class);
//s.addImplicitCollection(Persons.class,"perList");
//s.useAttributeFor(Person.class,"name");
//String xml=s.toXML(p);
File f=new File("c:/ddd.xml");
FileInputStream in=new FileInputStream(f);
Persons pp=(Persons)s.fromXML(in);
System.out.println(pp.getNumber());
String str =((Person)pp.getPerList().get(1)).getName();
System.out.println(str);
byte[] bytes=str.getBytes();
String res="";
if(ZipUtils.isUtf8(bytes)){
String tmpISO=new String(bytes,"ISO-8859-1");
res = new String(str.getBytes("ISO-8859-1"),"UTF-8");
System.out.println(1);
}else{
String tmpISO=new String(bytes,"ISO-8859-1");
res = new String(str.getBytes("GB2312"),"UTF-8");
System.out.println(2);
}
System.out.println(res);
// File f=new File("c:/ddd.xml");
// if(!f.exists()){
// f.createNewFile();
// }else{
//
// //FileUtils.deleteDirectory(f);
//
// }
// FileOutputStream out=new FileOutputStream(f);
// out.write(xml.getBytes());
// out.close();
} catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
}
}