我正面臨着訪問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」?>' –