IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

XML/XSL et SOAP Discussion :

comment faire une condition si cette balise n'existe pas dans cet element


Sujet :

XML/XSL et SOAP

  1. #1
    Membre du Club
    Inscrit en
    Novembre 2008
    Messages
    106
    Détails du profil
    Informations forums :
    Inscription : Novembre 2008
    Messages : 106
    Points : 60
    Points
    60
    Par défaut comment faire une condition si cette balise n'existe pas dans cet element
    Bonjour,

    un exemple de code xml
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
     
    <FinancialConcepts xmlns="" xmlns:xsi="http://xxxxxxx/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FinancialConcept.xsd">
     
      <FinancialConcept father="TermsCondsFXBase_A" fatherVersion="2" isReadOnly="false" name="TermsCondsFXFaderOpt_A" type="Concept" version="1">
        <Attribute includeChildren="false" listOfType="FXTrigger_A@1" 
        </Attribute>
      </FinancialConcept>
     
    </FinancialConcepts>
    pouvez vous me dire comment doit etre le code pour demande si une balise <comment> n'existe pas faire ...?

    je suis un peu perdu apres des tests non concluant.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    if (!courant.getChildren().equals("Comment"))
    j'ai essaye ceci mais ca ne marche pas.
    mais jarrive a faire ca mais pour un autre cas particulier:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    if (!courant.getChild("Comment").equals(null)){
    newstring.append("\n\n"+"#" + courant.getAttributeValue("father")+"\r\n");
    newstring.append("#" + courant.getAttributeValue("name")+ "\r\n");
    newstring.append("#"+courant.getChild("Comment").getTextTrim()+", \r\n");
    		}
    merci d'avance

  2. #2
    Membre du Club
    Inscrit en
    Novembre 2008
    Messages
    106
    Détails du profil
    Informations forums :
    Inscription : Novembre 2008
    Messages : 106
    Points : 60
    Points
    60
    Par défaut
    bon j'ai utilise try and catch finalement:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
     
    newstring.append("\n\n"+"# Type =" +courant.getAttributeValue("type")+ "\r\n");				
    newstring.append("# Concept=" +courant.getAttributeValue("name")+ "\r\n");
    newstring.append("# Father =" + courant.getAttributeValue("father")+"\r\n");
    try{
    newstring.append("# Comment = "+courant.getChild("Comment").getTextTrim()+", \r\n\n");
    }
    catch(Exception e){
    newstring.append("# No Comment \r\n\n");}
    }
    try{
    	text = newstring.toString();
    	_tampon.write(text);
    	_tampon.flush();
    	_tampon.close();	
    		}

  3. #3
    Membre du Club
    Inscrit en
    Novembre 2008
    Messages
    106
    Détails du profil
    Informations forums :
    Inscription : Novembre 2008
    Messages : 106
    Points : 60
    Points
    60
    Par défaut
    finalement c'est pas si genial des que j'ajoute d'autres instructions dans le try, car si la premiere balise comment n'existe pas, le reste n'est pas executer
    voici mon code, Quelqu'un peut-il m'apporter une solution svp?
    Un gd merci d'avance
    :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
    try{
    newstring.append("# Comment = ").
    append(courant.getChild("Comment").getTextTrim()).
    append(", \r\n\n");
    newstring.append("# PayoffBwd = ").
    append(courant.getChild("Script").getChild("PayoffBwd").getTextTrim()).
    append(", \r\n\n");
    newstring.append("# PayoffFwd = ").
    append(courant.getChild("Script").getChild("PayoffFwd").getTextTrim()).
    append(", \r\n\n");
    }
    catch(Exception e){newstring.append("# No Comment \r\n\n");}

  4. #4
    Membre du Club
    Inscrit en
    Novembre 2008
    Messages
    106
    Détails du profil
    Informations forums :
    Inscription : Novembre 2008
    Messages : 106
    Points : 60
    Points
    60
    Par défaut
    Excusez moi, voila j'ai fais comme ceci:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
     
    while(E.hasNext())
    		{
    //On recrée l'Element courant à chaque tour de boucle afin de
    //pouvoir utiliser les méthodes propres aux Element comme :
    //selectionner un noeud fils, modifier du texte, etc...
    Element courant = (Element)E.next();
    if (courant.getAttributeValue("type").equals("Deal")){
    newstring.append("\n\n# Type =").
    append(courant.getAttributeValue("type")).
    append("\r\n");			
    newstring.append("# Concept=").
    append(courant.getAttributeValue("name")).
    append( "\r\n");
    newstring.append("# Father =").
    append(courant.getAttributeValue("father")).
    append("\r\n\n");
    try{newstring.append("# Comment = ").
    append(courant.getChild("Comment").getTextTrim()).
    append(", \r\n");
    }
    catch(Exception e){newstring.append("# No Comment \r\n");}
    try{newstring.append("# PayoffBwd = ").
    append(courant.getChild("Script").getChild("PayoffBwd").getTextTrim()).
    append(", \r\n");}
    catch(Exception e){newstring.append("# No PayoffBwd \r\n");}
    try{newstring.append("# PayoffFwd = ").
    append(courant.getChild("Script").getChild("PayoffFwd").getTextTrim()).
    append(", \r\n\n");}
    catch(Exception e){newstring.append("# No PayoffFwd \r\n");}
    }
    try{
    text = newstring.toString();
    tampon.write(text);
    _tampon.flush();
    _tampon.close();	
    }
    catch(Exception e){System.out.println("Maybe The file recup.xls still open");}
    }
    mais j'ai l'impression que ce code peut-etre ameliore; pouvez vous m'aidez svp?

  5. #5
    Membre du Club
    Inscrit en
    Novembre 2008
    Messages
    106
    Détails du profil
    Informations forums :
    Inscription : Novembre 2008
    Messages : 106
    Points : 60
    Points
    60
    Par défaut
    je cloture, puisqu'il n'y a personne qui semble repondre, je pense qu'on ne peut pas l'ameliorer

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Comment faire une condition aux limites?
    Par j-mike dans le forum MATLAB
    Réponses: 10
    Dernier message: 09/10/2008, 14h28
  2. Comment faire une condition switch
    Par y-bab dans le forum IHM
    Réponses: 3
    Dernier message: 07/08/2008, 09h37
  3. Comment faire une condition en C#
    Par Calvein dans le forum ASP.NET
    Réponses: 3
    Dernier message: 02/06/2008, 10h31
  4. Comment faire une boucle avec cette procédure
    Par soffy dans le forum Macros et VBA Excel
    Réponses: 4
    Dernier message: 07/06/2007, 22h28
  5. Réponses: 16
    Dernier message: 06/04/2007, 13h36

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo