无法使用 LINQ to XML 浏览 GetListItems 的结果
我使用以下方式从 sharepoint wbesite 获取数据:
activeItemData = ws.GetListItems(listGUID, activeItemViewGUID,
qNode, vNode, rowLimit, null, "");
这是我从 sharepoint 获取的一条记录。
<**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>
现在,要使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试:
如果您查看行元素:
您缺少
ows_
属性名称。Try:
If you look at the row element:
<z:row ows_ID="1" ows_Title="My R.....
you were missing
ows_
from the attribute name.