java 字符串转换成document 取元素

byte[] bytes=new String("123456").getBytes();     //String.getBytes()返回一 个字节数组。
ByteArrayInputStream bin=new ByteArrayInputStream(bytes);
DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
DocumentBuilder builder=factory.newDocumentBuilder();

Document  document=duilder.parse(bin);

NodeList nodeList=document.getElementByTagName("abc");
String value=nodeList.item(0).getTextContent();  //这样就可以取得原本字符串里的xml元素了

猜你喜欢

转载自blog.csdn.net/maying0124/article/details/80680216