[Génération XML en JavaScript] Problème avec l'attribut xmlns
Bonjour,
je dois générer via un script javascript, un fichier xml de ce format :
Code:
1 2 3 4 5 6 7
| <?xml version="1.0" encoding="UTF-8"?>
<DemandeRemboursement xmlns="test/dossierEntrant">
<ENTETE>
<CODECAISSE>01371</CODECAISSE>
</ENTETE>
<pli rangPli="1">
... |
Pour faire, j'ai codé ceci :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| //Instanciation Document XML en mémoire
iXml = new ActiveXObject('Microsoft.XMLDOM');
iXml.async = false;
szXmlFileName = szMonFic+".xml";
// Initalize XML file
nodePli = iXml.createProcessingInstruction('xml', "version='1.0' encoding='UTF-8'");
iXml.appendChild(nodePli);
root = iXml.appendChild( iXml.createElement('DemandeRemboursement'));
attr = iXml.createAttribute('xmlns');
attr.value = ('tmp/dossierEntrant');
root.setAttributeNode(attr);
... |
Malheureusement, j'obtiens en sortie :
Code:
1 2 3 4 5 6 7
| <?xml version="1.0" encoding="UTF-8"?>
<DemandeRemboursement xmlns="test/dossierEntrant">
<ENTETE xmlns="">
<CODECAISSE>01371</CODECAISSE>
</ENTETE>
<pli xmlns="" rangPli="1">
... |
J'ai un peu cherché sur les forum et j'ai trouvé cette discussion (http://www.developpez.net/forums/sho...xmlns%3D%22%22) qui, en gros, explique que pour éviter la propagation du xmlns à vide dans les balises filles, je dois utiliser un createNode plutôt que createElement.
J'ai donc modifié mon script ainsi :
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| //Instanciation Document XML en mémoire
iXml = new ActiveXObject('Microsoft.XMLDOM');
iXml.async = false;
szXmlFileName = szMonFic+".xml";
// Initalize XML file
nodePli = iXml.createProcessingInstruction('xml', "version='1.0' encoding='UTF-8'");
iXml.appendChild(nodePli);
root = iXml.appendChild(iXml.createNode(1, 'DemandeRemboursement', 'tmp/dossierEntrant'));
... |
mais j'obtiens malheureusement le même résultat...
Est ce que quelqu'un voit où est mon erreur?
Merci d'avance.