Traduire un fichier txt en xml

mohamed222222 Messages postés 161 Date d'inscription mardi 12 juin 2007 Statut Membre Dernière intervention 22 avril 2009 - 9 août 2007 à 15:56
mohamed222222 Messages postés 161 Date d'inscription mardi 12 juin 2007 Statut Membre Dernière intervention 22 avril 2009 - 9 août 2007 à 16:31
Bonjour à tous!!!

Je voudrai traduire un fichier txt en fichier xml.

par exemple, j'ai dans mon fichier txt.

dupont,maxime,3,18;
durant,farid,5,48

Et je voudrai dans mon fichier xml :

je vous remercie de votre aide !!!!!!

2 réponses

Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 74
9 août 2007 à 16:26
applique ce genre de choses

Const sFileContent As String = "dupont,maxime,3,18" & vbNewLine & _
                             "durant,farid,5,48"

Private Sub Form_Load()
Dim oXML As DOMDocument
Dim oRoot As IXMLDOMElement
Dim i As Long
Dim xsHotels() As String
Dim xsParts() As String
  '# L'objet qui va nous permettre de manipuler notre document.
  Set oXML = New DOMDocument
  '# Racine de notre document
  oXML.appendChild oXML.createElement("personnes")
 
  '# On découpe la chaine d'entrée par lignes : une ligne = un hotel
  xsHotels = Split(sFileContent, vbNewLine)
  For i = 0 To UBound(xsHotels)
      '# On créé un élément 'hotel' pour chaque hotel
      Set oRoot = oXML.createElement("personne")
      oXML.childNodes(0).appendChild oRoot
     
      '# On découpe chacun des champs qui compose chaque ligne
      xsParts = Split(xsHotels(i), ";")
     
      '# On definit chaque attribut
      oRoot.setAttribute "nom", xsParts(0)
      oRoot.setAttribute "prenom", xsParts(1)
      oRoot.setAttribute "id", xsParts(2)
      oRoot.setAttribute "age", xsParts(3)
  Next i
 
  '# On crée le fichier XML
  oXML.save "C:\d.xml"
End Sub , ----
By Renfield

Renfield
Admin CodeS-SourceS- MVP Visual Basic
0
mohamed222222 Messages postés 161 Date d'inscription mardi 12 juin 2007 Statut Membre Dernière intervention 22 avril 2009
9 août 2007 à 16:31
en vb.net si possible.

Merci d'avance !!!!!
0
Rejoignez-nous