Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it
    Registrato dal
    Oct 2008
    Messaggi
    29

    Errore importazione da file XML in Java

    Ciao A tutti, spero di postare in modo corretto questa volta :-)
    Allora ho questo file XML:
    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>
    e Questa classe Java:
    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()); 					  					 				}
    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?
    Grazie mille per l'aiuto.
    Luigi

  2. #2
    Utente di HTML.it
    Registrato dal
    Feb 2007
    Messaggi
    4,157
    ehm potresti formattarli in modo che si leggano una riga sotto l'altra?

  3. #3
    Utente di HTML.it
    Registrato dal
    Oct 2008
    Messaggi
    29
    codice:
    <!--
    RSS generated by JIRA (4.2-beta3#581) at Wed Oct 13 04:01:24 CDT 2010
    -->
    <!-- If you wish to do custom client-side styling of RSS, uncomment this:
    <?xml-stylesheet href="http://jira.atlassian.com/styles/jiraxml2html.xsl" type="text/xsl"?>
    -->
    <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>
                <title>[TST-23142] as a student i must be up</title>
                                <key id="114580">TST-23142</key>
                <summary>as a student i must be up</summary>
                                <status id="1" iconUrl="http://jira.atlassian.com/images/icons/status_open.gif">Open</status>
                                                                                                                </item>
    
    <item>
    
                <title>[TST-22398] As a student  must try this feature</title>
                                <key id="110042">TST-22398</key>
                <summary>As a student  must try this feature</summary>
                                <status id="1" iconUrl="http://jira.atlassian.com/images/icons/status_open.gif">Open</status>
                                                                                                                </item>
    
    <item>
                <title>[TST-22363] As a student i must make this exam</title>
    
                                <key id="108940">TST-22363</key>
                <summary>As a student i must make this exam</summary>
                                <status id="1" iconUrl="http://jira.atlassian.com/images/icons/status_open.gif">Open</status>
                                                                                                                                              </item>
    
    <item>
                <title>[TST-22355] bye bye</title>
                                <key id="108860">TST-22355</key>
    
                <summary>bye bye</summary>
                                <status id="6" iconUrl="http://jira.atlassian.com/images/icons/status_closed.gif">Closed</status>
                                                                                                                </item>
    
    <item>
                <title>[TST-22353] test-uniba</title>
                                <key id="108816">TST-22353</key>
                <summary>test-uniba</summary>
    
                                <status id="5" iconUrl="http://jira.atlassian.com/images/icons/status_resolved.gif">Resolved</status>
                                                                                                                                              </item>
    </channel>
    </rss>
    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/title");
    						
    						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/description");
    						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());
    					
    
    					
    				}
    ecco qui scusami!

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.