Modifier attribut d'un doc xml

jesusonline Messages postés 6814 Date d'inscription dimanche 15 décembre 2002 Statut Membre Dernière intervention 13 octobre 2010 - 9 mai 2004 à 18:18
jesusonline Messages postés 6814 Date d'inscription dimanche 15 décembre 2002 Statut Membre Dernière intervention 13 octobre 2010 - 9 mai 2004 à 18:52
Bonjour,
j'ai un doc xml qui ressemble à ca :


    
      <li>[index.htm lien 1]</li>
      <li>[design.htm lien 2]</li>
      <li>[# lien 3]</li>
      <li>[# lien 4]</li>
      <li>[# lien 5]</li>
    



(bizarre ca ressemble à du xhtml ;) )

et je voudrais rajouter dans le code un attribut à la balise li pour que ca fasse qqchose comme ca :


<li>[index.htm lien 1]</li>
<li>[design.htm lien 2]</li>
<li id="current">[# lien 3]</li>
<li>[# lien 4]</li>
<li>[# lien 5]</li>


pour mettre l'attribut je connais juste son "index" dans l'exemple ce serait 3

j'ai cherché plusieurs solution pour faire un truc simple mais j'arrive pas

Je travail bien sur en vb.net :)

Merci

Cyril

1 réponse

jesusonline Messages postés 6814 Date d'inscription dimanche 15 décembre 2002 Statut Membre Dernière intervention 13 octobre 2010 29
9 mai 2004 à 18:52
j'ai trouvé deux solution pour ceux que ca interesse la premiere je l'ai mis en commentaire

donc voici :

Dim doc As New XmlDocument
doc.LoadXml("" & MenuHorizontal.InnerText & "")

'Dim mNodeChild As XmlNode
'mNodeChild = doc.DocumentElement.FirstChild

'Dim i As Integer = 0
'Do Until mNodeChild Is Nothing

' If i = _Category Then

' 'Create a new attribute.
' Dim mAttrib As XmlAttribute = doc.CreateAttribute("id")
' mAttrib.InnerText = "current"

' Dim mAttribCollection As XmlAttributeCollection = doc.DocumentElement.ChildNodes.Item(i - 1).Attributes
' mAttribCollection.Append(mAttrib)

' End If

' mNodeChild = mNodeChild.NextSibling
' i += 1
'Loop

Dim mNodeList As XmlNodeList = doc.SelectNodes("//li")

Dim i As Integer
For Each mNode As XmlNode In mNodeList
If i = _Category Then
Dim mAttrib As XmlAttribute = doc.CreateAttribute("id")
mNode.Attributes.Append(mAttrib).Value = "current"
Exit For
End If
i += 1
Next

MenuHorizontal.InnerHtml = doc.InnerXml

Cyril
0
Rejoignez-nous