Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. Linq to Xml Programming

Linq to Xml Programming

Scheduled Pinned Locked Moved XML / XSL
csharpdatabaselinqxmlannouncement
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JimBob SquarePants
    wrote on last edited by
    #1

    Hi there, I'm trying to teach myself linq to xml and I've been struggling to implement a linq to xml class with which I can update values in a given xml file. I'm a total beginner at this so I have probably made a simple mistake. My Base class is as follows:

    Public Class WebSite
    Private _Id As String
    Public Property Id() As String
    Get
    Return (_Id)
    End Get
    Set(ByVal value As String)
    _Id = value
    End Set
    End Property
    Private _Link As String
    Public Property Link() As String
    Get
    Return (_Link)
    End Get
    Set(ByVal value As String)
    _Link = value
    End Set
    End Property

    Private \_Picture As String
    Public Property Picture() As String
        Get
            Return (\_Picture)
        End Get
        Set(ByVal value As String)
            \_Picture = value
        End Set
    End Property
    
    Private \_ModifiedOn As String
    Public Property ModifiedOn() As String
        Get
            Return (\_ModifiedOn)
        End Get
        Set(ByVal value As String)
            \_ModifiedOn = value
        End Set
    End Property
    
    Public Sub New(ByVal xElement As XElement)
        Id = xElement.Attribute("Id").Value
        Link = xElement.Element("Link").Value
        Picture = xElement.Element("Picture").Value
        ModifiedOn = xElement.Element("ModifiedOn").Value
    End Sub
    Private \_xElement As XElement
    Public Property xElement() As XElement
        Get
            Return New XElement("Website", New XAttribute("Id", Id), New XElement("Link", Link), New XElement("Picture", Picture), New XElement("ModifiedOn", ModifiedOn))
    
        End Get
        Set(ByVal value As XElement)
            \_xElement = value 
        End Set
    End Property
    

    The sub that I am trying to implement is as follows:

    Public Class Portfolio
    Inherits List(Of WebSite)

    Public Sub UpdateWebsite(ByVal xmlFile As String, ByVal WebId As String, ByVal WebLink As String, ByVal WebPic As String, ByVal WebMod As String)
        Dim doc As XDocument = XDocument.Load(xmlFile)
        Dim query = From xElem In doc.Descendants("Website") \_
                    Where xElem.@Id = WebId \_
        Select New WebSite(xElem)
    
    
        With query.SingleOrDefault
            .Id = WebId
            .Link = WebLink
            .Picture = WebPic
            .ModifiedOn = WebMod
        End With
    
        Me.Clear()
    
    L 1 Reply Last reply
    0
    • J JimBob SquarePants

      Hi there, I'm trying to teach myself linq to xml and I've been struggling to implement a linq to xml class with which I can update values in a given xml file. I'm a total beginner at this so I have probably made a simple mistake. My Base class is as follows:

      Public Class WebSite
      Private _Id As String
      Public Property Id() As String
      Get
      Return (_Id)
      End Get
      Set(ByVal value As String)
      _Id = value
      End Set
      End Property
      Private _Link As String
      Public Property Link() As String
      Get
      Return (_Link)
      End Get
      Set(ByVal value As String)
      _Link = value
      End Set
      End Property

      Private \_Picture As String
      Public Property Picture() As String
          Get
              Return (\_Picture)
          End Get
          Set(ByVal value As String)
              \_Picture = value
          End Set
      End Property
      
      Private \_ModifiedOn As String
      Public Property ModifiedOn() As String
          Get
              Return (\_ModifiedOn)
          End Get
          Set(ByVal value As String)
              \_ModifiedOn = value
          End Set
      End Property
      
      Public Sub New(ByVal xElement As XElement)
          Id = xElement.Attribute("Id").Value
          Link = xElement.Element("Link").Value
          Picture = xElement.Element("Picture").Value
          ModifiedOn = xElement.Element("ModifiedOn").Value
      End Sub
      Private \_xElement As XElement
      Public Property xElement() As XElement
          Get
              Return New XElement("Website", New XAttribute("Id", Id), New XElement("Link", Link), New XElement("Picture", Picture), New XElement("ModifiedOn", ModifiedOn))
      
          End Get
          Set(ByVal value As XElement)
              \_xElement = value 
          End Set
      End Property
      

      The sub that I am trying to implement is as follows:

      Public Class Portfolio
      Inherits List(Of WebSite)

      Public Sub UpdateWebsite(ByVal xmlFile As String, ByVal WebId As String, ByVal WebLink As String, ByVal WebPic As String, ByVal WebMod As String)
          Dim doc As XDocument = XDocument.Load(xmlFile)
          Dim query = From xElem In doc.Descendants("Website") \_
                      Where xElem.@Id = WebId \_
          Select New WebSite(xElem)
      
      
          With query.SingleOrDefault
              .Id = WebId
              .Link = WebLink
              .Picture = WebPic
              .ModifiedOn = WebMod
          End With
      
          Me.Clear()
      
      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      Don't cross post

      J 1 Reply Last reply
      0
      • L led mike

        Don't cross post

        J Offline
        J Offline
        JimBob SquarePants
        wrote on last edited by
        #3

        My apologies, I didn't quite know where to post it as the question covers both fields. Still stuck though.

        JimBob SquarePants ******************************************************************* "He took everything personally, including our royalties!" David St.Hubbins, Spinal Tap about Ian Faith, their ex-manager *******************************************************************

        G 1 Reply Last reply
        0
        • J JimBob SquarePants

          My apologies, I didn't quite know where to post it as the question covers both fields. Still stuck though.

          JimBob SquarePants ******************************************************************* "He took everything personally, including our royalties!" David St.Hubbins, Spinal Tap about Ian Faith, their ex-manager *******************************************************************

          G Offline
          G Offline
          George L Jackson
          wrote on last edited by
          #4

          Your question involves LINQ usage. Thus, you should post it under the .NET Framework forum. Since it is written in Visual Basic, you could have place it there as a second choice. However, you should still only post it in one forum.

          "We make a living by what we get, we make a life by what we give." --Winston Churchill

          modified on Saturday, March 28, 2009 5:11 PM

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups