【发布时间】:2017-03-16 16:25:45
【问题描述】:
我正在像这样查询我的 SP 列表:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://myspsite/_api/web/lists/getByTitle('the%20title')/items");
request.Method = "GET";
request.ContentType = "text/xml";
request.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream receiveStream = response.GetResponseStream();
StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);
XDocument xd = XDocument.Load(readStream);
response.Close();
readStream.Close();
这给了我以下信息:
<feed xml:base="http://myspsite/_api/" xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml">
<id>090ds-211312-asdadsasd</id>
<title />
<updated>2011-03-16T15:33:25Z</updated>
<entry m:etag=""7"">
<id>a4846531-dae6-413c-bbbe-b3012342ewerred0d1</id>
<category term="SP.Data.My.ListItem" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
<link rel="edit" href="Web/Lists(guid'0eef-a924-471e-80f0-8d71erwsdf3d6d')/Items(10)" />
<title />
<updated>2012-03-16T15:33:25Z</updated>
<author>
<name />
</author>
<content type="application/xml">
<m:properties>
<d:FileSystemObjectType m:type="Edm.Int32">0</d:FileSystemObjectType>
<d:Id m:type="Edm.Int32">38</d:Id>
<d:ContentTypeId>0x010400C64826486CBEE74BBFF0werwerewsdfD</d:ContentTypeId>
<d:Title>This is my Title</d:Title>
<d:Body>This is the body</d:Body>
<d:Summaries>This is the body summary</d:Summaries>
<d:Include m:type="Edm.Boolean">false</d:Include>
<d:Add_Date m:type="Edm.DateTime">2015-10-07T04:00:00Z</d:Add_Date>
<d:ID m:type="Edm.Int32">38</d:ID>
<d:OData__UIVersionString>1.0</d:OData__UIVersionString>
<d:GUID m:type="Edm.Guid">69504c8e-6897-49e6-926d-d54c900524e5</d:GUID>
</m:properties>
</content>
</entry>
<entry m:etag=""7"">
<id>a4846531-dae6-413c-bbbe-b301234234ewd0d1</id>
<category term="SP.Data.My.ListItem" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
<link rel="edit" href="Web/Lists(guid'0ee1d7ef-a924-471e-80f0-8d71erwsdf3d6d')/Items(38)" />
<title />
<updated>2012-03-16T15:33:25Z</updated>
<author>
<name />
</author>
<content type="application/xml">
<m:properties>
<d:FileSystemObjectType m:type="Edm.Int32">0</d:FileSystemObjectType>
<d:Id m:type="Edm.Int32">38</d:Id>
<d:ContentTypeId>0x010400C64826486CBEE7sdfsfdsdf3D</d:ContentTypeId>
<d:Title>This is my Title</d:Title>
<d:Body>This is the body</d:Body>
<d:Summaries>This is the body summary</d:Summaries>
<d:Include m:type="Edm.Boolean">false</d:Include>
<d:Add_Date m:type="Edm.DateTime">2015-10-07T04:00:00Z</d:Add_Date>
<d:ID m:type="Edm.Int32">38</d:ID>
<d:OData__UIVersionString>1.0</d:OData__UIVersionString>
<d:GUID m:type="Edm.Guid">69504c8e-6897-49e6-926d-d54c900524e5</d:GUID>
</m:properties>
</content>
</entry>
//... more entry
</feed>
如何获取每个entry 的d:Title 和d:Body?
我尝试使用:
foreach (XElement element in xd.Descendants("entry"))
{
Console.WriteLine(element);
}
但这没有用。
请帮我获取entry中的节点。
【问题讨论】:
标签: c# xml linq-to-xml sharepoint-2013