2010-11-08 72 views
0

Ok, donc je commence à construire un lecteur Youtube, et j'ai un objet XmlDocument pour stocker les méta-informations de la vidéo, mais j'ai des problèmes pour trouver comment mettre à jour le document XML.XmlDocument | Mise à jour des noeuds

Heres mon code à ce jour:

public void UpdateVideo(string video_id, string title, string download_url) 
{ 
    if (this.DownloadExists(video_id)) 
    { 
     XmlNodeList Videos = Document.GetElementsByTagName(video_id); 

     if (Videos.Count == 1) 
     { 
      XmlNode Video = Videos[0]; 

      //Update the Title 
      XmlNodeList Properties = Video.ChildNodes; 

      //Title 
      foreach (XmlNode Property in Properties) 
      { 
       switch (Property.Name.ToLower()) 
       { 
        case "title": 
         Property.InnerText = title; 
        break; 
        case "download_url": 
         Property.InnerText = download_url; 
        break; 
       } 

       //Update the property back to Video object...... 
       //Update the Video back to the Videos etc....... 

      } 
     } 
     Document.Save(StorageFile); 
    } 
} 

@see commentaires ci-dessus

Ceci est essentiellement une petite VideoStorage classe, qui lit/écrit dans un document XML.

données XML de l'échantillon est comme ceci:

<?xml version="1.0" encoding="iso-8859-1"?> 
<videos> 
    <pqky5B179nM> 
     <id>pqky5B179nM</id> 
     <title>will.i.am, Nicki Minaj - Check It Out</title> 
     <videod_url>http://www.youtube.com/watch?v=pqky5B179nM</videod_url> 
    </pqky5B179nM> 
</videos> 

si les gars vous avez une meilleure solution pour faire cette im toutes les oreilles.

Merci à l'avance.

+0

donc ce qui est le problème? Comment ne met-il PAS à jour? – gideon

Répondre

0

Peut-être est plus lisible pour vous:

Private Sub SaveItem(ByVal Title As String, ByVal GroupData As String) 
      'Save Data in an XML file (Timo Böhme, www.goldengel.ch) 
      Dim fi As New IO.FileInfo(TB.SystemMain.AppPath & "ButtonLayout.xml") 'Define the file to write in 
      Dim writer As New Xml.XmlTextWriter(fi.FullName, System.Text.Encoding.UTF8) 'create new XML reader class 


      writer.WriteStartDocument() 'start writing Xml document 

        writer.WriteStartElement("PositionInfos") 'go or create to PositionInfos tag 

        writer.WriteStartElement("PositionInfo") 'go or create to PositionInfo tag 
          writer.WriteAttributeString("Title", Title) 'write attribut Title 
          writer.WriteAttributeString("GroupData", GroupData) 'write attribut GroupData 
        writer.WriteEndElement() 'close PositionInfo tag 

      writer.WriteEndElement() 'close PositionInfos tag 
      writer.WriteEndDocument() 'close document tag 

      writer.Flush() 'write to disk 
      writer.Close() 'close file 
    End Sub