hente data fra xml efter id spm?
Hejsa...Mit problem er at jeg ikke har prøvet og læse fra en xml fil før! :-(
Jeg har en metode som, jeg vil have til at læse fra et xml ark.
Den skal hente dataene, ud fra id. Jeg har en klasse som jeg laver objekter i som hedder statusCode2. Min hensigt er så at binde disse data, til objekterne (har lavet det med en datareader masser af gange!)
statusCodeDetails2 klassen:
-------------------------------------------------
Public Class StatusCodeDetails2
Private c_sStatusCode As String
Private c_sStatusDescription As String
Public Property StatusCode() As String
Get
Return c_sStatusCode
End Get
Set(ByVal Value As String)
c_sStatusCode = Value
End Set
End Property
Public Property Description() As String
Get
Return c_sStatusDescription
End Get
Set(ByVal Value As String)
c_sStatusDescription = Value
End Set
End Property
End Class
-------------------------------------------------
Mit xml ark ser således ud:
------------------------------------------------
<?xml version="1.0" encoding="utf-8" ?>
<StatusCode>
<Code>
<Id>404</Id>
<Description>Siden kunne ikke findes. Fejl type: HTTP 404</Description>
</Code>
<Code>
<Id>500</Id>
<Description>Siden kunne ikke findes. Fejl type: HTTP 500</Description>
</Code>
</StatusCode>
------------------------------------------------
Min metode som skal læse xml:
------------------------------------------------
Private Const doc As String = "StatusCode.xml"
Public Function GetStatusCode(ByVal codeId As String) As XmlReader
Dim oXmlReader As XmlReader
Try
Dim oDetails As New Library.StatusCode2
While oXmlReader.Read = True
With oDetails
.StatusCode = XmlReader("Code").ToString
.Description = XmlReader("Description").ToString
End With
End While
Return XmlReader
Catch ex As FileNotFoundException
Throw New FileNotFoundException("XML filen StatusCode.xml kunne ikke findes", ex)
Catch ex As Exception
Throw ex
End Try
End Function
---------------------------------------------------
Håber på lidt hjælp!
;-)
Mvh
DK
