无法使用 LINQ to XML 浏览 GetListItems 的结果

发布于 2024-09-24 02:02:50 字数 1428 浏览 6 评论 0原文

我使用以下方式从 sharepoint wbesite 获取数据:

activeItemData = ws.GetListItems(listGUID, activeItemViewGUID, 
     qNode, vNode, rowLimit, null, "");

这是我从 sharepoint 获取的一条记录。

<**rs:data** ItemCount="1" ListItemCollectionPositionNext="Paged=TRUE&amp;p_ID=1" xmlns:rs="urn:schemas-microsoft-com:rowset">
   <**z:row** ows_ID="1" ows_Title="My RFC Title number one" ows_GUID="{A73B8E91-98BF-4CA7-8ADB-A3B933D6D8DA}" ows_Req_x0020_Number="112343" ows_Ends="2010-07-17 00:00:00" ows_MetaInfo="1;#" ows__ModerationStatus="0" ows__Level="1" ows_Start="2010-07-08 00:00:00" ows_owshiddenversion="13" ows_UniqueId="1;#{EA9E9C87-1B28-47DE-B7F4-DA4ADDF913F6}" ows_FSObjType="1;#0" ows_Created="2010-07-07 11:05:56" ows_Status="1. In-Work" ows_FileRef="1;#sites/PS/Lists/Change Control/1_.000" xmlns:z="#RowsetSchema" />
</rs:data>

现在,要使用 LINQ to XML,我将保存此数据的对象从 XMLDocument 更改为 XDocument

XDocument results = XDocument.Parse(activeItemData.OuterXml);

,问题是,一旦我尝试浏览数据以获取 ID 和标题,就会收到错误:对象引用未设置为实例一个物体的。

这是我尝试用来获取这些字段的代码片段:

 var items = from item in results.Descendants(XName.Get("row", "#RowsetSchema"))
       select new
           {
               Title = item.Attribute("Title").Value,
               Id = item.Attribute("ID").Value 
           };

似乎该项目无法找到此 XName 元素

谢谢

I'm getting the data from sharepoint wbesite using

activeItemData = ws.GetListItems(listGUID, activeItemViewGUID, 
     qNode, vNode, rowLimit, null, "");

Here is what I got from the sharepoint its one record.

<**rs:data** ItemCount="1" ListItemCollectionPositionNext="Paged=TRUE&p_ID=1" xmlns:rs="urn:schemas-microsoft-com:rowset">
   <**z:row** ows_ID="1" ows_Title="My RFC Title number one" ows_GUID="{A73B8E91-98BF-4CA7-8ADB-A3B933D6D8DA}" ows_Req_x0020_Number="112343" ows_Ends="2010-07-17 00:00:00" ows_MetaInfo="1;#" ows__ModerationStatus="0" ows__Level="1" ows_Start="2010-07-08 00:00:00" ows_owshiddenversion="13" ows_UniqueId="1;#{EA9E9C87-1B28-47DE-B7F4-DA4ADDF913F6}" ows_FSObjType="1;#0" ows_Created="2010-07-07 11:05:56" ows_Status="1. In-Work" ows_FileRef="1;#sites/PS/Lists/Change Control/1_.000" xmlns:z="#RowsetSchema" />
</rs:data>

Now to use LINQ to XML I change the object which hold this data from XMLDocument to XDocument by using

XDocument results = XDocument.Parse(activeItemData.OuterXml);

and the problem is that once I try to browse through the data to obtain ID and Title I got the error: Object reference not set to an instance of an object.

Here is the piece of code which I'm trying to use to get those fields:

 var items = from item in results.Descendants(XName.Get("row", "#RowsetSchema"))
       select new
           {
               Title = item.Attribute("Title").Value,
               Id = item.Attribute("ID").Value 
           };

Seems that item is unable to locate this XName element

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光无声 2024-10-01 02:02:50

尝试:

 var items = from item in results.Descendants(XName.Get("row", "#RowsetSchema"))
       select new
           {
               Title = item.Attribute("ows_Title").Value,
               Id = item.Attribute("ows_ID").Value 
           };

如果您查看行元素:

您缺少 ows_属性名称。

Try:

 var items = from item in results.Descendants(XName.Get("row", "#RowsetSchema"))
       select new
           {
               Title = item.Attribute("ows_Title").Value,
               Id = item.Attribute("ows_ID").Value 
           };

If you look at the row element:

<z:row ows_ID="1" ows_Title="My R.....

you were missing ows_ from the attribute name.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文