2016-03-24 6 views
1

Ben aşağıdaki kod parçacığını vardır:Bir XmlElement öğesinin özniteliğini, artık sınıf oluşturmadan çift olarak nasıl alabilirim?

benim XML belgesinin aşağıdaki bölümde istinaden
<XmlElement("point")> _ 
       Public Property points() As List(Of Double) 
        Get 
         Return myPoints 
        End Get 
        Set(value As List(Of Double)) 
         myPoints = value 
        End Set 
       End Property 

:

<upperLimit color="red"> 
       <point y="12"/> 
       <point y="13"/> 
       <point y="14"/> 
       <point y="15"/> 
       <point y="16"/> 
      </upperLimit> 

Ben bir oluşturmak istiyorum benim VB programı anlatmaya çalışıyorum XML belgesindeki "puanlar" listesinden çiftler listesi. Ne anlayamıyorum ben oldukça XmlAttributey

Yani böyle bir şey (i bu yanlış olduğunu biliyorum)

<XmlElement("point").XmlAttribute("y")> _ <-- Notice this line!! 
       Public Property points() As List(Of Double) 
        Get 
         Return myPoints 
        End Get 
        Set(value As List(Of Double)) 
         myPoints = value 
        End Set 
       End Property 

innerText ama almak XmlElementpoint bakıp değil bunu söyleyebilir nasıl Gördüğüm tek diğer alternatif, değeri ilişkilendirmek için ANOTHER sınıf oluşturmaktı. Bunun için bir cevap bulmak için google'da ne arayacağımı da düşünemiyorum ... Teşekkürler!

cevap

0

bu

Imports System.Xml 
Imports System.Xml.Linq 
Module Module1 

    Sub Main() 
     Dim xml As String = _ 
     "<upperLimit color=""red"">" & _ 
      "<point y=""12""/>" & _ 
      "<point y=""13""/>" & _ 
      "<point y=""14""/>" & _ 
      "<point y=""15""/>" & _ 
      "<point y=""16""/>" & _ 
     "</upperLimit>" 

     Dim doc As XDocument = XDocument.Parse(xml) 

     Dim results As List(Of Double) = doc.Descendants("point").Select(Function(x) Double.Parse(x.Attribute("y").Value)).ToList() 
    End Sub 

End Module 
deneyin
İlgili konular