天天看點

解析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