Ciao A tutti, spero di postare in modo corretto questa volta :-)
Allora ho questo file XML:
e Questa classe Java:codice:<rss version="0.92"> <channel> <title>Atlassian JIRA</title> <link>http://jira.atlassian.com/secure/Iss...rentUser%28%29</link> <description>An XML representation of a search request</description> <language>en-uk</language> <issue start="0" end="5" total="5"/> <build-info> <version>4.2-beta3</version> <build-number>581</build-number> <build-date>27-09-2010</build-date> <edition>enterprise</edition> </build-info> <item> <key id="114580">TST-23142</key> <summary>as a student i must be up</summary> </item> <item> <key id="110042">TST-22398</key> <summary>As a student must try this feature</summary> </item> <item> <key id="108940">TST-22363</key> <summary>As a student i must make this exam</summary> </item> <item> <key id="108860">TST-22355</key> <summary>bye bye</summary> </item> <item> <key id="108816">TST-22353</key> <summary>test-uniba</summary> </item> </channel> </rss>
Non rieesco ad importare i campi item con quella espressione //channel//item/summary, se invece scrivo //channel//title mi importa solo quelle del tag channel. Praticamente non riesce ad andare in profondità nell'albero. Sto impazzendo! Qualche soluzione?codice:public static void readFile(File f3) { try{ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(f3); XPathFactory factory1 = XPathFactory.newInstance(); XPath xpath = factory1.newXPath(); XPathExpression expr; Object result; expr = xpath.compile("//channel//item/key"); result = expr.evaluate(doc, XPathConstants.NODESET); NodeList nodeListId = (NodeList) result; for (int i = 0; i < nodeListId.getLength(); i++){ id.offer(nodeListId.item(i).getTextContent()); } expr = xpath.compile("//channel//item/title"); result = expr.evaluate(doc, XPathConstants.NODESET); NodeList nodeListTitle = (NodeList) result; for (int i = 0; i < nodeListTitle.getLength(); i++){ storyText.offer(nodeListTitle.item(i).getTextContent()); jID++; id.offer(Integer.toString(jID)); } expr = xpath.compile("//language"); result = expr.evaluate(doc, XPathConstants.NODESET); NodeList nodeListBody = (NodeList) result; for (int i = 0; i < nodeListBody.getLength(); i++) note.offer(nodeListBody.item(i).getTextContent()); }
Grazie mille per l'aiuto.
Luigi

Rispondi quotando