您可以尝试使用XPath方法简化XML解析:
InputStream response = new ByteArrayInputStream("<Response> <aa> " + "<Fromhere> <a1>Content</a1> <a2>Content</a2> </Fromhere> " + "</aa> </Response>".getBytes()); documentBuilder builder = documentBuilderFactory .newInstance().newdocumentBuilder();document doc = builder.parse(response);XPath xpath = XPathFactory.newInstance().newXPath();XPathexpression expr = xpath.compile("string(/Response/aa/FromHere)");String result = (String)expr.evaluate(doc, XPathConstants.STRING);请注意,我没有尝试过此代码。它可能需要调整。



