繁体   English   中英

在BlackBerry上解析XML字符串

[英]Parse XML string on BlackBerry

我正在尝试使用以下代码解析XML,但是BlackBerry JDE中不提供StringReader。 什么是正确的方法?

            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();
            InputSource is = new InputSource();
            is.setCharacterStream(new StringReader(xmlRecords));
            Document doc = db.parse(is);
String xmlString = "<xml> </xml>" // your xml string    

ByteArrayInputStream bis = new ByteArrayInputStream(xmlString.getBytes("UTF-8"));

Document doc = builder.parse(bis);

试试看

如果要使用来自服务器的数据来构建DOM,最好直接使用DocumentBuilder解析InputStream,而不是将数据读入String并尝试使用它。 一种方法是:

Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(input);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM