2010-11-24 90 views
5

我收到錯誤調用函數GetListItems,但有點奇怪,因爲它在Visual Studio 2008 Express中可用,但在Visual Basic 2010 Express中不可用:無法將System.Xml.XmlNode轉換爲System.Xml.Linq.XElement

Dim ndQuery As XmlNode = xmlDoc.CreateNode(XmlNodeType.Element, "Query", "") 

    Dim ndViewFields As XmlNode = xmlDoc.CreateNode(XmlNodeType.Element, "ViewFields", "") 
    Dim ndQueryOptions As XmlNode = xmlDoc.CreateNode(XmlNodeType.Element, "QueryOptions", "") 

    ndQueryOptions.InnerXml = "<IncludeMandatoryColumns>False</IncludeMandatoryColumns>" & _ 
           "<DateInUtc>True</DateInUtc>" 

    ndViewFields.InnerXml = "<FieldRef Name=""LinkFilename"" />" & _ 
          "<FieldRef Name=""Empresa"" />" & _ 
          "<FieldRef Name=""Puesto"" />" & _ 
          "<FieldRef Name=""Fecha_x0020_Vigente"" />" & _ 
          "<FieldRef Name=""Oferta_x0020_vigente"" />" 

    ndQuery.InnerXml = "" 

    Try 

     Dim ndListItems As XmlNode = IntranetLists.GetListItems(ListUUID, Nothing, _ 
                ndQuery, ndViewFields, Nothing, ndQueryOptions, Nothing) 

這是函數調用i'm:

Public Function GetListItems(ByVal listName As String, ByVal viewName As String, ByVal query As System.Xml.Linq.XElement, ByVal viewFields As System.Xml.Linq.XElement, ByVal rowLimit As String, ByVal queryOptions As System.Xml.Linq.XElement, ByVal webID As String) As System.Xml.Linq.XElement 
     Dim inValue As ListasIntranetGureak.GetListItemsRequest = New ListasIntranetGureak.GetListItemsRequest() 
     inValue.Body = New ListasIntranetGureak.GetListItemsRequestBody() 
     inValue.Body.listName = listName 
     inValue.Body.viewName = viewName 
     inValue.Body.query = query 
     inValue.Body.viewFields = viewFields 
     inValue.Body.rowLimit = rowLimit 
     inValue.Body.queryOptions = queryOptions 
     inValue.Body.webID = webID 
     Dim retVal As ListasIntranetGureak.GetListItemsResponse = CType(Me,ListasIntranetGureak.ListsSoap).GetListItems(inValue) 
     Return retVal.Body.GetListItemsResult 
    End Function 
+2

如果它不能正常工作,請告訴我們*的方式*它不工作。請參閱http://tinyurl.com/so-hints – 2010-11-24 07:52:48

回答

9

我沒有VB 2008年得心應手,但據我所知有有從未過任何自動轉換(隱式或明確的)在XElement和- LINQ到XML主要是一個並行 DOM的實現,只有一些東西(如XmlReader作爲源)的共同點。

但是;在處理問題方面,我可以建議的最好方法是使用xml;一個C#示例(使用CreateReader,以避免通過string去):

XElement el = new XElement("foo", 
    new XAttribute("abc","def"), new XElement("bar")); 
var doc = new XmlDocument(); 
using (var reader = el.CreateReader()) { 
    doc.Load(reader); 
} 
XmlNode node = doc.DocumentElement; // node could also be typed as XmlElement 

,並把它再次轉換(匹配問題的標題):

XElement andBackAgain; 
using(var reader = new XmlNodeReader(node)) { 
    andBackAgain = XElement.Load(reader); 
} 
相關問題