Click here to Skip to main content
15,885,216 members
Home / Discussions / XML / XSL
   

XML / XSL

 
QuestionUpdate InfoPath option button using XML Pin
hoonzis26-Mar-09 5:54
hoonzis26-Mar-09 5:54 
QuestionInclude superscript and subscript in a XML. Pin
Vishnu Nath26-Mar-09 3:05
Vishnu Nath26-Mar-09 3:05 
AnswerRe: Include superscript and subscript in a XML. Pin
scottgp26-Mar-09 3:32
professionalscottgp26-Mar-09 3:32 
QuestionHow to include Word Place Holders into my xslt? Pin
Tejabhiram25-Mar-09 3:58
Tejabhiram25-Mar-09 3:58 
AnswerRe: How to include Word Place Holders into my xslt? Pin
led mike25-Mar-09 11:38
led mike25-Mar-09 11:38 
GeneralRe: How to include Word Place Holders into my xslt? Pin
Tejabhiram25-Mar-09 18:58
Tejabhiram25-Mar-09 18:58 
GeneralRe: How to include Word Place Holders into my xslt? Pin
led mike26-Mar-09 4:50
led mike26-Mar-09 4:50 
QuestionLinq to Xml Programming Pin
JimBob SquarePants24-Mar-09 6:58
JimBob SquarePants24-Mar-09 6:58 
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()
        AddRange(query)


        Save(xmlFile)
            
    End Sub


    Public Sub Save(ByVal xmlFile As String)

        Dim xml As New XElement("Portfolio", From p In Me _
            Select p.xElement)

        xml.Save(xmlFile)
    End Sub

End Class


The Xml file I am trying to edit:

<?xml version="1.0" encoding="utf-8"?>
<Portfolio>
  <Website Id="1">
    <Link>Test Link</Link>
    <Picture>Test Image</Picture>
    <ModifiedOn>Test Date</ModifiedOn>
  </Website>
</Portfolio>


I just can't seem to get the the class to update.

I hate getting stuck like this!

Any Ideas.

Many Thanks in advance.

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

AnswerCross Posted Pin
led mike24-Mar-09 8:44
led mike24-Mar-09 8:44 
GeneralRe: Cross Posted Pin
JimBob SquarePants24-Mar-09 13:54
JimBob SquarePants24-Mar-09 13:54 
AnswerRe: Cross Posted [modified] Pin
George L. Jackson28-Mar-09 11:05
George L. Jackson28-Mar-09 11:05 
QuestionTransform XML document Pin
sonukadole23-Mar-09 20:39
sonukadole23-Mar-09 20:39 
AnswerRe: Transform XML document [modified] Pin
George L. Jackson24-Mar-09 3:47
George L. Jackson24-Mar-09 3:47 
AnswerRe: Transform XML document Pin
logiclabz27-Mar-09 8:09
logiclabz27-Mar-09 8:09 
GeneralRe: Transform XML document Pin
George L. Jackson28-Mar-09 11:03
George L. Jackson28-Mar-09 11:03 
QuestionSerialize object with XSLT ref Pin
Ido22-Mar-09 22:20
Ido22-Mar-09 22:20 
AnswerThe Answer is: Pin
Ido22-Mar-09 23:06
Ido22-Mar-09 23:06 
QuestionAttribute centric XML file from SQL Server Pin
CrimeanTurtle200822-Mar-09 0:06
CrimeanTurtle200822-Mar-09 0:06 
AnswerRe: Attribute centric XML file from SQL Server Pin
led mike23-Mar-09 5:36
led mike23-Mar-09 5:36 
QuestionSQL 2 XML DB Pin
ahmedsamir21-Mar-09 6:47
ahmedsamir21-Mar-09 6:47 
AnswerRe: SQL 2 XML DB Pin
led mike23-Mar-09 5:38
led mike23-Mar-09 5:38 
QuestionXML parser selection Pin
mango_lier18-Mar-09 11:00
mango_lier18-Mar-09 11:00 
QuestionC# Help Read XML Settings Pin
Tiago Conceição17-Mar-09 12:23
Tiago Conceição17-Mar-09 12:23 
AnswerRe: C# Help Read XML Settings Pin
led mike18-Mar-09 5:25
led mike18-Mar-09 5:25 
Questionxml transformation Pin
sonukadole16-Mar-09 19:15
sonukadole16-Mar-09 19:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.