Java 从字符串解析xml
我正在解析一个xml,数据来自一个字符串。我正在使用以下代码进行解析:-Java 从字符串解析xml,java,xml,blackberry,Java,Xml,Blackberry,我正在解析一个xml,数据来自一个字符串。我正在使用以下代码进行解析:- DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory .newInstance(); DocumentBuilder docBuilder = docBuilderFactory .newDocumentBuilder(); docBuilder.isValidating(); ByteArrayInput
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory
.newInstance();
DocumentBuilder docBuilder = docBuilderFactory
.newDocumentBuilder();
docBuilder.isValidating();
ByteArrayInputStream ba= new ByteArrayInputStream(connect.content.getBytes("UTF-8"));
doc = docBuilder.parse(ba);
doc.getDocumentElement().normalize();
NodeList locationStatus = doc.getElementsByTagName("street");
for (int i = 0; i < locationStatus.getLength(); i++) {
Node locationValue = locationStatus.item(i).getChildNodes().item(0);
_node.addElement(locationValue.getNodeValue());
}
String [] nodeString = new String[_node.size()];
_node.copyInto(nodeString);
add(new LabelField(nodeString.length+""));
DocumentBuilderFactory docBuilderFactory=DocumentBuilderFactory
.newInstance();
DocumentBuilder docBuilder=docBuilderFactory
.newDocumentBuilder();
isValidating();
ByteArrayInputStream ba=新的ByteArrayInputStream(connect.content.getBytes(“UTF-8”);
doc=docBuilder.parse(ba);
doc.getDocumentElement().normalize();
节点列表位置状态=doc.getElementsByTagName(“街道”);
对于(int i=0;i
但是这个代码给出了错误,我不知道错误在哪里
请帮帮我
提前感谢使用XStream或JAXB您尝试过这种方法吗
SAXParserImpl saxparser = new SAXParserImpl();
ResponseHandler handler = new ResponseHandler();
ByteArrayInputStream stream = new ByteArrayInputStream(xmlresp.getBytes());
public class ResponseHandler extends DefaultHandler
{
public void startElement(String uri, String localName,
String qName,Attributes attributes) {}
public void characters(char[] ch, int start, int length)
{
tempVal = new String(ch, start, length);
}
public void endElement(String uri, String localName,
String qName) throws SAXException {}
}
错误的细节是什么?你有堆栈跟踪吗?你能发布错误消息和堆栈跟踪吗?这也会有助于查看你试图解析的XML。BlackBerry上是否有此功能?