Fichier xml: lire les attributs

cs_chris21 Messages postés 19 Date d'inscription mercredi 16 juillet 2003 Statut Membre Dernière intervention 3 octobre 2003 - 19 sept. 2003 à 09:00
cs_chris21 Messages postés 19 Date d'inscription mercredi 16 juillet 2003 Statut Membre Dernière intervention 3 octobre 2003 - 19 sept. 2003 à 11:22
bonjour à tous j'ai un fichier xml de ce type:[blue]<rutas>
<ruta tipo="central" url="/imagenes/home/home/directorio_gg/sansebastian03_gg.swf"
enlace="/edicion/cm/bin/"/>
<ruta tipo="central" url="/imagenes/home/home/directorio_mm/abajoelamor_mm.swf"
enlace="/edicion/cm/bin/"/>
<ruta tipo="central" url="/imagenes/home/home/directorio_mm/seanconnery_mm.swf"
enlace="/edicion/cm/bin/"/>
<ruta tipo="central" url="/imagenes/home/home/directorio_mm/soldadosdesalamina_mm.swf"
enlace="/edicion/cm/bin/"/>
<ruta tipo="central" url="/imagenes/home/home/directorio_mm/lascarasderipley_mm.swf"
enlace="/edicion/cm/bin"/>
<ruta tipo="promocion" url="/imagenes/home/home/directorio_g/cartelera_g.swf"/>
</rutas>
[blue]
En fait j'aimerais pouvoir lire les attributs de mes nodes et je n'y arrive pas.. Qu'elle est la syntaxe??
Merci

5 réponses

Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 74
19 sept. 2003 à 09:26
as tu ajouté une reference a 'Microsoft XML' ?

ca te donnes acces a tout un tas de fonctions qui viendraient a bout de ton probleme.

By Renfield

[mailto:thomas_reynald@msn.com mailto:thomas_reynald@msn.com]

Aucune touche n'a été blessée lors de la saisie de ce texte.......... ;)
0
cs_chris21 Messages postés 19 Date d'inscription mercredi 16 juillet 2003 Statut Membre Dernière intervention 3 octobre 2003
19 sept. 2003 à 09:31
oui bien sûr, j'arrive à lire le xml, mais pas à séparer les éléments. j'arrive à compter le nombre de nodes, etc... mais je trouve l'aide pas très claire.
0
Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 74
19 sept. 2003 à 10:11
J'ai mis ton fichier dans un fichier.xml, et j'ai fais ca :

Private Sub Form_Load()
    Dim XML As New DOMDocument30
    XML.Load App.Path & "\Fil.xml"
    
    Dim Rutas As IXMLDOMNode
    Set Rutas = XML.firstChild
    
    Dim Node As IXMLDOMNode
    
    For Each Node In Rutas.childNodes        Debug.Print "Ruta", "tipo " & NodeAttribute(Node, "tipo"), "url " & NodeAttribute(Node, "url"), "enlace = " & NodeAttribute(Node, "enlace")
    Next Node
    End
End Sub

Function NodeAttribute(lNode As IXMLDOMNode, AttributeName As String) As String
    Dim NodeAtt As IXMLDOMAttribute
    For Each NodeAtt In lNode.Attributes
        If NodeAtt.Name = AttributeName Then
            NodeAttribute = NodeAtt.Text
            Exit Function
        End If
    Next NodeAtt
    Set NodeAtt = Nothing
End Function


By Renfield

[mailto:thomas_reynald@msn.com mailto:thomas_reynald@msn.com]

Aucune touche n'a été blessée lors de la saisie de ce texte.......... ;)
0
cs_chris21 Messages postés 19 Date d'inscription mercredi 16 juillet 2003 Statut Membre Dernière intervention 3 octobre 2003
19 sept. 2003 à 10:28
ça ne marche pas chez moi, t'as mis quoi comme référence? j'ai ajouté microsoft ado et microsoft xml 2.0.
merci pour ton aide
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
cs_chris21 Messages postés 19 Date d'inscription mercredi 16 juillet 2003 Statut Membre Dernière intervention 3 octobre 2003
19 sept. 2003 à 11:22
j'ai trouvé, par exemple pour afficher les url dans un msgbox, voici mon code:
Function chargement(fichero)
Dim numerorutas As Integer
Dim i As Integer
Dim objxml As New MSXML.DOMDocument
Dim xmllist As MSXML.IXMLDOMNodeList
Dim xmlnode As MSXML.IXMLDOMNode
Dim argumentos As MSXML.IXMLDOMAttribute
objxml.validateOnParse = False
objxml.async = False
If objxml.Load(Dir1.Path & "" & fichero) Then
'MsgBox ("objxml.Text " & objxml.Text)
Set xmllist = objxml.selectNodes("//rutas/ruta")
'MsgBox argumentos
numerorutas = xmllist.length
MsgBox ("xmllist.lenght " & numerorutas)
For Each xmlnode In xmllist
Set argumentos = xmlnode.Attributes(1)
MsgBox argumentos.Text
'MsgBox ("xmlnode.Text " & xmlnode.Text)
i = i + 1
Next
MsgBox ("numero de attributos " & i)
On Error GoTo ErrorHandler
objxml.validateOnParse = True
Else
MsgBox "res"
End If
Set objxml = Nothing
Exit Function
ErrorHandler:
MsgBox Err.Description
Set objxml = Nothing
End Function
:)
0
Rejoignez-nous