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

Format d'échange (XML, JSON...) Java Discussion :

Parser un xml contenant des caractères spéciaux


Sujet :

Format d'échange (XML, JSON...) Java

  1. #1
    Expert éminent sénior
    Avatar de Baptiste Wicht
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2005
    Messages
    7 431
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : Suisse

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2005
    Messages : 7 431
    Points : 21 324
    Points
    21 324
    Par défaut Parser un xml contenant des caractères spéciaux
    Bonjour

    J'ai besoin de parser un xml contenant des chaines de ce type là :

    §SÅO8Л°n7OS’žiÁR?qvlmÅq^Š\u8482 ‡
    J'ai donc une exception qui est levée :

    org.jdom.input.JDOMParseException: Error on line 5 of document file:/C:/Documents%20and%20Settings/Baptiste/Bureau/passwd/Special.xml: Invalid byte 1 of 1-byte UTF-8 sequence.
    J'en viens donc à mes question : comment spécifier l'encodage avec JDOM ? Et aussi, quel codage dois-je employer ?


  2. #2
    Expert éminent sénior
    Avatar de Baptiste Wicht
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2005
    Messages
    7 431
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : Suisse

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2005
    Messages : 7 431
    Points : 21 324
    Points
    21 324
    Par défaut
    Personne ne sait comment gérer des caractères spéciaux en xml ?

  3. #3
    Expert éminent sénior
    Avatar de Baptiste Wicht
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2005
    Messages
    7 431
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : Suisse

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2005
    Messages : 7 431
    Points : 21 324
    Points
    21 324
    Par défaut
    En fait, il suffit de modifier le paramètre encoding du fichier...

    mais je sais pas quel encore mettre...

    Sachant que ce que je chercher à encoder est le résultat d'un cryptage SHA-512...

  4. #4
    Expert éminent sénior
    Avatar de Baptiste Wicht
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2005
    Messages
    7 431
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : Suisse

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2005
    Messages : 7 431
    Points : 21 324
    Points
    21 324
    Par défaut
    J'ai essayé en spécifiant un encodage UTF-16 :

    FEFF<?xml version="1.0" encoding="UTF-16BE"?>
    <balises>
    <balise>
    <value1>Bonjour</pseudo>
    <value2>¶…m:›u8216 LÀŸÓä-‰ÓÓ’V®¾Ø'P}h6úoží;?Æ</password>
    </balise>
    </balises>
    mais maintenant, JDOM me crache une erreur :

    Error on line 1 of document : Content is not allowed in prolog.
    Quelqu'un sait comment régler ce problème ?

  5. #5
    Expert éminent sénior
    Avatar de Baptiste Wicht
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2005
    Messages
    7 431
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : Suisse

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2005
    Messages : 7 431
    Points : 21 324
    Points
    21 324
    Par défaut
    Alors, y a t'il une autre API qui permet de manipuler des XML contenant des caractères spéciaux ?

    Sinon, je crois que je tout foutre dans un fichier texte....

  6. #6
    Membre éclairé Avatar de g_rare
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    608
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2005
    Messages : 608
    Points : 683
    Points
    683
    Par défaut
    Citation Envoyé par wichtounet
    comment spécifier l'encodage avec JDOM ? Et aussi, quel codage dois-je employer ?
    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
     
    /**
     * http://www.jdom.org/docs/apidocs/org/jdom/input/SAXBuilder.html#build(java.io.Reader)
     * 
     * It's the programmer's responsibility to make sure the reader matches
     * the encoding of the file. It's often easier and safer to use an
     * InputStream rather than a Reader, and to let the parser auto-detect
     * the encoding from the XML declaration.
     */
    /**
     * http://www.jdom.org/docs/apidocs/org/jdom/output/XMLOutputter.html
     * 
     * Unfortunatly there is currently no way to know the original encoding
     * of the document.
     */
    Citation Envoyé par wichtounet
    §SÅO8Л°n7OS’žiÁR?qvlmÅq^Š\u8482 ‡
    Citation Envoyé par wichtounet
    ce que je chercher à encoder est le résultat d'un cryptage SHA-512
    Les bits de condensé produits par toutes les fonctions de la famille SHA (Secure Hash Algorithm) sont "toujours" en notation hexadécimale (0-9+a-f).

    Citation Envoyé par wichtounet
    Error on line 1 of document : Content is not allowed in prolog.
    Essaye en rajouter une ligne vide à la fin de ton fichier XML.

    " Jag blev dömd för fildelning och allt jag fick var en sketen t-shirt. " (tankafritt.nu)
    PAS DE REPONSE PAR MESSAGE PRIVE ! Penser au bouton Résolu en bas de la discussion...

  7. #7
    Membre du Club
    Profil pro
    Inscrit en
    Juillet 2006
    Messages
    57
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France, Haute Savoie (Rhône Alpes)

    Informations forums :
    Inscription : Juillet 2006
    Messages : 57
    Points : 68
    Points
    68
    Par défaut
    ou de supprimer "FEFF" au début si c pas une erreur de copier coller

    essaye aussi de mettre tout ça dans un CDATA

    ou encore si c'est toi qui écrit le fichier en java essaye
    org.apache.axis.components.encoding.XMLEncoderFactory..getDefaultEncoder().encode(taChaine)
    quand tu le mets dans ton fichier

  8. #8
    Expert éminent sénior
    Avatar de Baptiste Wicht
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2005
    Messages
    7 431
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : Suisse

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2005
    Messages : 7 431
    Points : 21 324
    Points
    21 324
    Par défaut
    Merci de vos réponses

    Je vais tester tout ca

    Et je vous dis ce que ca donne.

  9. #9
    Expert éminent sénior
    Avatar de Baptiste Wicht
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2005
    Messages
    7 431
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : Suisse

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2005
    Messages : 7 431
    Points : 21 324
    Points
    21 324
    Par défaut
    Bon, ben ca marche toujours pas...

    Je crois que ce projet va rester encore un moment aux oubliettes...

    J'ai essayé en mettant le <![CDATA[, j'ai essayé en supprimmant le FFEF au départ (en fait, c'est pour indiquer un truc au format de codage), mais pas moyen...

    Ca m'énèrve

  10. #10
    Membre du Club
    Profil pro
    Inscrit en
    Juillet 2006
    Messages
    57
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France, Haute Savoie (Rhône Alpes)

    Informations forums :
    Inscription : Juillet 2006
    Messages : 57
    Points : 68
    Points
    68
    Par défaut
    et en encryptant à la génération ?

  11. #11
    Expert éminent sénior
    Avatar de Baptiste Wicht
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2005
    Messages
    7 431
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : Suisse

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2005
    Messages : 7 431
    Points : 21 324
    Points
    21 324
    Par défaut
    Citation Envoyé par XSeb74
    et en encryptant à la génération ?
    Ben, faudrait d'abord que je sache d'ou tu sors ta classe ?

  12. #12
    Membre éclairé Avatar de sozie9372
    Inscrit en
    Mai 2005
    Messages
    713
    Détails du profil
    Informations personnelles :
    Âge : 41

    Informations forums :
    Inscription : Mai 2005
    Messages : 713
    Points : 724
    Points
    724
    Par défaut
    Je viens de tester chez moi, et ca fonctionne correctement, je pensais qu'en changeant l'encoding, j'aurai une erreur mais non :
    J'ai testé avec ISO-8859-1, ISO-8859-2, ISO-8859-1 et UTF-8, aucun problème...
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    document.addContent(new ProcessingInstruction("encoding","ISO-8859-1"));
    Le xml de test :
    <message>
    <settings direction="Downlink" description="Packet Access Reject" spy-message-type="rrr"
    spy-name="§SÅO8Л°n7OS’žiÁR?qvlmÅq^Š\u8482 ‡" layer="RLC_MAC_LAYER" channel="PCCH"/>
    <ttcn>
    <line>§SÅO8Л°n7OS’žiÁR?qvlmÅq^Š\u8482 ‡</line>
    <cref> </cref>
    <label-id></label-id>
    <header> </header>
    <verdict-id> </verdict-id>
    </ttcn>
    </message>
    Et l'affichage que j'obtiens :
    $Header
    $BehaviourLine
    $LabelId
    $Line [0] §SÅO8Ð?°n7OS??iÁR?qvlmÅq^?\u8482 ?
    $Cref
    $VerdictId ( )
    $End_BehaviourLine
    Fais pas attention à la mise en forme, c'est un projet sur lequel je suis
    "Il y a 3 personnes en ce monde sur qui tu peux compter : moi, le pape et le cavalier solitaire ! "
    Penser à svp

  13. #13
    Expert éminent sénior
    Avatar de Baptiste Wicht
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2005
    Messages
    7 431
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : Suisse

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2005
    Messages : 7 431
    Points : 21 324
    Points
    21 324
    Par défaut
    Citation Envoyé par sozie9372
    Je viens de tester chez moi, et ca fonctionne correctement, je pensais qu'en changeant l'encoding, j'aurai une erreur mais non :
    J'ai testé avec ISO-8859-1, ISO-8859-2, ISO-8859-1 et UTF-8, aucun problème...
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    document.addContent(new ProcessingInstruction("encoding","ISO-8859-1"));
    Le xml de test :

    Et l'affichage que j'obtiens :

    Fais pas attention à la mise en forme, c'est un projet sur lequel je suis
    C'est louche, car j'ai essayé avec l'encodage ISO-8859-1 et UTF-8 et ca marchait pas...

    Tu le lis comment ton fichier ?

  14. #14
    Membre éclairé Avatar de sozie9372
    Inscrit en
    Mai 2005
    Messages
    713
    Détails du profil
    Informations personnelles :
    Âge : 41

    Informations forums :
    Inscription : Mai 2005
    Messages : 713
    Points : 724
    Points
    724
    Par défaut
    Comme dans les tutos

    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
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
     
    public void build(String fileName) {
    		SAXBuilder sxb = new SAXBuilder();
    		try {
    			document = sxb.build(new File(fileName));
                //document.addContent(new ProcessingInstruction("encoding","ISO-8859-1"));
    		root = document.getRootElement();
    			// load hashtable
    			loadCorrespondencesTable();
    			displayAll();
    		} catch (JDOMException e) {
    			e.printStackTrace();
    			JOptionPane.showMessageDialog(null, e.getMessage(), "Error",
    					JOptionPane.ERROR_MESSAGE);
    		} catch (IOException e) {
    			e.printStackTrace();
    			JOptionPane.showMessageDialog(null, e.getMessage(), "Error",
    					JOptionPane.ERROR_MESSAGE);
    		}
    	}
     
    	/**
             * 
             */
    	private void loadCorrespondencesTable() {
    		List listMsg = root.getChildren("message");
    		List nodesList = null;
    		Iterator i = listMsg.iterator();
    		String currentMsg;
    		int j = 0;
    		Element ttcnNode, currentNode;
    		BehaviourLine bLine = null;
    		while (i.hasNext()) {
    			currentNode = (Element) i.next();
    			currentMsg = currentNode.getChild("settings").getAttributeValue(
    					"description");
    			if (!currentMsg.replaceAll("\\s", "").equals("")) {
    				System.out.println("current message : " + currentMsg);
    				ttcnNode = (Element) currentNode.getChild("ttcn");
    				bLine = new BehaviourLine(j++);
    				bLine.setCref(ttcnNode.getChildText("cref"));
    				bLine.setHeader(ttcnNode.getChildText("header"));
    				bLine.setLabelId(ttcnNode.getChildText("label-id"));
    				bLine.setLine(ttcnNode.getChildText("line"));
    				bLine.setVerdict(ttcnNode.getChildText("verdict-id"));
    				hCorrespondancesSpyTTCN.put(currentMsg, bLine);
    			}
     
    		}
    	}
     
    	/**
             * 
             */
    	private void displayAll() {
    		Enumeration e = hCorrespondancesSpyTTCN.keys();
    		while (e.hasMoreElements()) {
    			System.out.println(hCorrespondancesSpyTTCN.get(
    					e.nextElement().toString()).toString());
    		}
    	}
    "Il y a 3 personnes en ce monde sur qui tu peux compter : moi, le pape et le cavalier solitaire ! "
    Penser à svp

  15. #15
    Expert éminent sénior
    Avatar de Baptiste Wicht
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2005
    Messages
    7 431
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : Suisse

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2005
    Messages : 7 431
    Points : 21 324
    Points
    21 324
    Par défaut
    Il me semble pourtant que je fais comme toi...

    Je vais regarder ça ce soir

  16. #16
    Membre du Club
    Profil pro
    Inscrit en
    Juillet 2006
    Messages
    57
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France, Haute Savoie (Rhône Alpes)

    Informations forums :
    Inscription : Juillet 2006
    Messages : 57
    Points : 68
    Points
    68
    Par défaut
    Citation Envoyé par wichtounet
    Ben, faudrait d'abord que je sache d'ou tu sors ta classe ?
    axis, c marqué dessus

  17. #17
    Expert éminent sénior
    Avatar de Baptiste Wicht
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2005
    Messages
    7 431
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : Suisse

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2005
    Messages : 7 431
    Points : 21 324
    Points
    21 324
    Par défaut
    Citation Envoyé par XSeb74
    axis, c marqué dessus
    Je vais aller voir ca alors

Discussions similaires

  1. json_encode remplace les mot contenant des caractères spéciaux par null
    Par tojosource dans le forum Général JavaScript
    Réponses: 1
    Dernier message: 04/06/2010, 20h04
  2. Passage de paramètres contenant des caractères spéciaux (+, -,etc.)
    Par Mil17 dans le forum Général JavaScript
    Réponses: 3
    Dernier message: 05/06/2008, 11h21
  3. Probléme avec requétes contenant des caractéres spéciaux
    Par dragonfly dans le forum Requêtes
    Réponses: 1
    Dernier message: 08/11/2007, 17h20
  4. Nettoyer une chaine contenant des caractères spéciaux?
    Par adil_vpb dans le forum Général JavaScript
    Réponses: 7
    Dernier message: 30/05/2007, 15h47
  5. Réponses: 1
    Dernier message: 22/01/2007, 20h33

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