我正面临着访问XML值的困难,任何人都可以让我知道我在想什么。Java XML解析问题
String xml = "<Standard p1:oid=\"00000000-0000-0000-0000-000000f674c1\"\n" +
" xmlns:p1=\"com.iMelt.metaCore.DataObjects.Core\" xmlns=\"com.iMelt.Car.Model.Core\"\n" +
" reasonCode=\"0\">\n" +
" <p1:__info p1:eid=\"00000000-0000-0000-0000-000000000000\">\n" +
" <p1:creationDate>2016-05-28T20:33:45.337+00:00</p1:creationDate>\n" +
" <p1:lastEditorRef>Administrator</p1:lastEditorRef>\n" +
" <p1:version>5</p1:version>\n" +
" </p1:__info>\n" +
" <ChangeState>Approved</ChangeState></Standard>";
byte[] byteArray = xml.getBytes();
ByteArrayInputStream inputStream = new ByteArrayInputStream(byteArray);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(inputStream);
XPathFactory xpathfactory = XPathFactory.newInstance();
XPath xpath = xpathfactory.newXPath();
XPathExpression expr = xpath.compile("/Standard/ChangeState");
Object result = expr.evaluate(doc, XPathConstants.NODESET);
你面对什么样的困难?确切的问题是什么! –
我也尝试过/ ChangeState,并没有在结果中填充“Approved”值 – developer
您的XML缺少XML减速度<?xml version =“1.0”encoding =“UTF-8”?>' –