如何在Asp中从iphone的http帖子中获取所有节点?

时间:2012-05-03 15:06:05

标签: iphone asp.net vb.net http-post

我只想从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

请heeeeeelp:)

1 个答案:

答案 0 :(得分:1)

Dim doc as XmlDocument = New XmlDocument()
doc.LoadXml(value)
For Each node as XmlNode in doc.SelectNodes("/Matches/Match")
    'Do work
Next