天天看点

解析XML字符串

怎么解析一个xml字符串?我不是第一次看到有人问这个问题了..汗

1.使用stringreader

解析XML字符串

 document doc  =  builder.parse(  new  java.io.stringreader(str)); 

2.使用documenthelper.parsetext()

解析XML字符串

 string text  =   " <person> <name>james</name> </person> " ; 

解析XML字符串

document document  =  documenthelper.parsetext(text); 

3.最苯的方法:

解析XML字符串

 document doc   =   builder.parse(  new   bytearrayinputstream(str.getbytes())); 

解析XML字符串

文章转自庄周梦蝶  ,原文发布5.16