Modification d'un fichier XML en VB

soda_cops Messages postés 4 Date d'inscription samedi 13 décembre 2003 Statut Membre Dernière intervention 11 novembre 2010 - 25 août 2004 à 21:46
cs_EBArtSoft Messages postés 4525 Date d'inscription dimanche 29 septembre 2002 Statut Modérateur Dernière intervention 22 avril 2019 - 25 août 2004 à 22:50
J'essaie de modifier un fichier XML (via MSXML4.dll) mais sans y parvenir.

La lecture du fichier ne pose pas de problème.
Les fonctions 'Create..' semble marché mais la fonction 'Save' ne produit qu'un document en tout point identique au fichier d'origine
(C'est à dire sans tenir compte des modifications apportées)

Merci

Soda Cops

2 réponses

cs_dragon Messages postés 2336 Date d'inscription samedi 14 juillet 2001 Statut Membre Dernière intervention 5 mai 2009 6
25 août 2004 à 21:57
fait a modif comme si c'était un fichier texte tout simplement
-------------------------------------------------
Dragon alias aussi Waxime mais bon, pas le gout de refaire un nouveau profil lol
-------------------------------------------------
0
cs_EBArtSoft Messages postés 4525 Date d'inscription dimanche 29 septembre 2002 Statut Modérateur Dernière intervention 22 avril 2019 9
25 août 2004 à 22:50
Voici un exemple de gestion de fichier ini avec XML Lecture/Ecriture :

Function XMLNode(ByRef wParent As Object, ByVal wName As String, ByVal wValue As String) As IXMLDOMNode
    Set XMLNode = wParent.ownerDocument.createElement(wName)
    XMLNode.Text = wValue
    wParent.appendChild wParent.ownerDocument.createTextNode(Space$(4))
    wParent.appendChild XMLNode
    wParent.appendChild wParent.ownerDocument.createTextNode(vbCrLf)
End Function

Function XMLAttr(ByRef wParent As Object, ByVal wName As String, ByVal wValue As String) As IXMLDOMAttribute
    Set XMLAttr = wParent.ownerDocument.createAttribute(wName)
    XMLAttr.Value = wValue
    wParent.Attributes.setNamedItem XMLAttr
End Function

Sub XMLLoadSettings(ByVal wFileName As String)
    On Error GoTo Xe
    Dim vNode As IXMLDOMNode
    Dim vXML  As DOMDocument
    Set vXML = New DOMDocument
    vXML.Load wFileName
    For Each vNode In vXML.childNodes(0).childNodes
        Select Case vNode.baseName
        Case "Skin":    mSkin = UnQuote(vNode.Text)
        Case "Left":    mLastLeft = vNode.Text
        Case "Top":     mLastTop = vNode.Text
        End Select
    Next
    Set vXML = Nothing
Xi: Exit Sub
Xe: MsgBox Err.Description, vbCritical
    Resume Xi
End Sub

Sub XMLSaveSettings(ByVal wFileName As String)
    On Error GoTo Xe
    Dim vRoot As IXMLDOMNode
    Dim vNode As IXMLDOMNode
    Dim vXML  As DOMDocument
    Set vXML = New DOMDocument
    Set vRoot = vXML.createElement(XMLSECTION)
    vXML.appendChild vRoot
    vRoot.appendChild vXML.createTextNode(vbCrLf)
    XMLNode vRoot, "Skin", Quote(mSkin)
    XMLNode vRoot, "Left", mLastLeft
    XMLNode vRoot, "Top", mLastTop
    vXML.save wFileName
    Set vXML = Nothing
Xi: Exit Sub
Xe: MsgBox Err.Description, vbCritical
    Resume Xi
End Sub


ça peut peut etre t'aider...

@+

E.B.
0
Rejoignez-nous