iPhoneからのxml投稿でevryノードをキャッチしたいだけです。たとえば、これは「取得」する必要があるxmlファイルです
<Matchs>
<owner>Me</owner>
<typeAction>Me</typeAction>
<match id=21>sept 3 2011 </match>
<match id=22>sept 4 2011 </match>
<match id=23>sept 5 2011 </match>
</Matchs>
すべてのノードを取得できますが、同じ名前のノードが複数ある場合、その方法がわかりません...
これは値を取得するための私のコードです:
Public Shared Function TryParse(ByVal value As String, ByRef notification As MatchModel) As Boolean
Dim success As Boolean = False
notification = Nothing
Try
Dim xReader As System.Xml.XmlReader = System.Xml.XmlReader.Create(New System.IO.StringReader(value))
Dim element As System.Xml.Linq.XElement = System.Xml.Linq.XElement.Load(xReader)
notification = New MatchModel()
' Populate the top XML elements values
Dim wItem As System.Xml.Linq.XElement = Nothing
Dim actual As matchAlone = Nothing
While xReader.MoveToElement()
If element IsNot Nothing Then
wItem = element.Element("match")
actual.Description = GetXElementValue(element, "match")
actual.Id = GetWorkItemAttributeValue(wItem, "id")
End If
End While
notification.Owner = GetXElementValue(element, "owner")
notification.TypeAction = GetXElementValue(element, "typeAction")
success = True
Catch e As Exception
Console.WriteLine(e.Message)
End Try
Return success
End Function
Public Shared Function GetXElementValue(ByVal element As System.Xml.Linq.XElement, ByVal name As System.Xml.Linq.XName) As String
Dim value As String = Nothing
If element IsNot Nothing Then
value = element.Element(name).Value
End If
Return value
End Function
Public Shared Function GetWorkItemAttributeValue(ByVal element As System.Xml.Linq.XElement, ByVal name As System.Xml.Linq.XName) As String
Dim value As String = Nothing
If element IsNot Nothing Then
value = element.Attribute(name).Value
End If
Return value
End Function
笑ってください:)