Hello,
J'aimerai convertir un fichier CSV en XML en respectant un schéma spécifique. Comment dois-procéder ?
Connaîtriez vous des outils gratuits qui pourraient faire cela ?
Sinon, dois-je utiliser du XSL/XPath ?
Merci à tous.
Version imprimable
Hello,
J'aimerai convertir un fichier CSV en XML en respectant un schéma spécifique. Comment dois-procéder ?
Connaîtriez vous des outils gratuits qui pourraient faire cela ?
Sinon, dois-je utiliser du XSL/XPath ?
Merci à tous.
pour faire du cvs vers xml xslt ne t'ai d'aucune aide en effet xslt prend comme fichier de départ un fichier xml pour fournir du txt, xml, xhtml, ....
concernant ton problème moi j'utilise un de mes programmes écrit en python qui transforme le cvs en xml puis j'utilise une feuille de style xsl pour obtenir un xml dans le schéma souhaité
Donc en résumé
code python xslt + xalan
cvs --------------------> xml ----------------------------> xml souhaité
un bout de code python
mon fichier csvCode:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 from xml.dom.minidom import Document import csv cr = csv.reader(open("/home/fraoustin/sample.csv","rb"), delimiter=";") xmldoc = Document() xmltag = xmldoc.createElement("root") x=0 for i in cr: xmlchild = xmldoc.createElement("child") for j in i: xmlchild2 = xmldoc.createElement("elt%s"%x) xmlchild2.appendChild(xmldoc.createTextNode(j)) xmlchild.appendChild(xmlchild2) x=x+1 x=0 xmltag.appendChild(xmlchild) xmldoc.appendChild(xmltag) print xmldoc.toxml()
Code:
1
2
3
4 "a";"b";"c" "1";"2";"3" "1";"2";"3"