无法返回Xml.Nodelist对象?

时间:2013-11-24 21:36:37

标签: asp.net xml vb.net asmx

我正在尝试返回一个匹配的XML节点列表,我希望使用客户端,即迭代并显示,但是当我尝试返回Nodelist对象时出现以下错误:

  

要成为XML可序列化,从IEnumerable继承的类型必须具有   Add(System.Object)在其所有级别的实现   继承层次结构。 System.Xml.XmlNodeList未实现   添加(System.Object的)。

守则:

Private Function getAllPlayList(ByVal userID As String) As System.Xml.XmlNodeList
    Dim list As System.Xml.XmlNodeList
    Dim xPath As String = "//*[starts-with(@ID, 'B00')]"
    list = xmlDataPlaylists.DocumentElement.SelectNodes(xPath)
    Return list
End Function

<WebMethod()> _
Public Function GetPlaylists(ByVal userID As String) As System.Xml.XmlNodeList
    Return getAllPlayList(userID)
End Function

Xml我试图从以下位置返回匹配的节点:

<?xml version="1.0" encoding="utf-8"?>
<Playlists>
    <Playlist ID="B00237185@studentmail.uws.ac.uk+POP">
        <Song name="Test Song">
            <Album>Test Album 1</Album>
            <Artist>Test Artist 1</Artist>
            <Title>Test Song 1</Title> 
            <Favourite>False</Favourite>
        </Song>
        <Song name="Test Song 2">
            <Album>Test Album 2</Album>
            <Artist>Test Artist 2</Artist>
            <Title>Test Song 2</Title> 
            <Favourite>False</Favourite>
        </Song>     
    </Playlist> 
        <Playlist ID="B00237185@studentmail.uws.ac.uk+ROCK">
        <Song name="Test Song">
            <Album>Rock Album 1</Album>
            <Artist>Rock Artist 1</Artist>
            <Title>Rock Song 1</Title> 
            <Favourite>False</Favourite>
        </Song>
        <Song name="Test Song 2">
            <Album>Rock Album 2</Album>
            <Artist>Rock Artist 2</Artist>
            <Title>Rock Song 2</Title> 
            <Favourite>False</Favourite>
        </Song>     
    </Playlist>
    <Playlist ID="B00162755@studentmail.uws.ac.uk+POP">
        <Song name="Test Song">
            <Album>Test Album</Album>
            <Artist>Test Artist</Artist>
            <Title>Test Song</Title> 
            <Favourite>False</Favourite>
        </Song>
    </Playlist>
</Playlists>

我可以很容易地返回单个节点,但是当我尝试返回列表时,我得到了提到的错误

0 个答案:

没有答案