Partage
  • Partager sur Facebook
  • Partager sur Twitter

[Blackberry] afficher une image dans un fichier XML

    26 juillet 2012 à 17:12:26

    Bonjour, j'essaie d'afficher des avatars stockés dans un fichier xml mais je ne sais pas comment faire, j'ai considéré les images comme étant des noeuds textes mais ça marche pas.
    voici mon code
    public final class XMLParser extends MainScreen
    {
        // Statics -------------------------------------------------------------------------------------
        private static final String _xmlFileName = "/xml/Annuaire.xml";
        
        
        
        
        public XMLParser() 
        {
            setTitle("XML Demo");
            
            try 
            {
                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                DocumentBuilder builder = factory.newDocumentBuilder();
                InputStream inputStream = getClass().getResourceAsStream( _xmlFileName );
                Document document = builder.parse( inputStream );
                
                
                Element rootElement = document.getDocumentElement();
                rootElement.normalize();
                
                
                displayNode( rootElement, 0 );
            } 
            catch ( Exception e ) 
            {
                System.out.println( e.toString() );
            }
        }
        
      
        private void displayNode( Node node, int depth ) 
        {        
            
            if ( node.getNodeType() == Node.ELEMENT_NODE ) 
            {
                StringBuffer buffer = new StringBuffer();
                NodeList childNodes = node.getChildNodes();
                int numChildren = childNodes.getLength();
                Node firstChild = childNodes.item( 0 );
                
               
                if ( numChildren == 1 && firstChild.getNodeType() == Node.TEXT_NODE ) 
                {
                    buffer.append( firstChild.getNodeValue() );
                    add( new LabelField( buffer.toString() ) );
    
                    
                } 
                else 
                {
                   
                	if(node.getNodeValue()  != null)
                	{
                		buffer.append(node.getNodeValue());
                	add( new LabelField( buffer.toString() ) );
                	}
                    
                    
                    for ( int i = 0; i < numChildren; ++i ) 
                    {
                        displayNode( childNodes.item( i ), depth + 1 );
                    }
                }
            
            }
            else 
            {
                
                String nodeValue = node.getNodeValue();
                if ( nodeValue.trim().length() != 0 ) 
                {	
                	HorizontalFieldManager manager = new HorizontalFieldManager();
                    StringBuffer buffer = new StringBuffer();
                    buffer.append( nodeValue );
                    add( manager );
                    manager.add(new LabelField(buffer.toString()));
                }
            }
        }
        
        
        
        
    
    
    }
    


    et voici mon fichier xml


    <annuaire>
    - <personne type="étudiant">
    	  <image><img src = "/Essai0/res/img/p1.jpg"/></image>
    	<nom>TEST</nom> 
      <prenom>Test</prenom> 
      <email>test@xml.com</email>
    	 
      </personne>
    - <personne type="étudiant">
    	  <image><img src = "/Essai0/res/img/p1.jpg"/></image>
      <nom>NOM</nom> 
      <prenom>PRENOM</prenom> 
      <email>test@test.com</email> 
      </personne>
      </annuaire>
    




    est ce que je dois utiliser xslt? ou il existe des commandes DOM pour afficher les images?
    Merci
    • Partager sur Facebook
    • Partager sur Twitter

    [Blackberry] afficher une image dans un fichier XML

    × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
    × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
    • Editeur
    • Markdown