Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从RESTAPI调用获取xml节点值_C#_Xml_Rest_Sharepoint Online - Fatal编程技术网

C# 从RESTAPI调用获取xml节点值

C# 从RESTAPI调用获取xml节点值,c#,xml,rest,sharepoint-online,C#,Xml,Rest,Sharepoint Online,我们正在尝试使用c#从下面列表的条目中获取Url 编辑: 使用Alex Thompson提供的解决方案,我们能够缩小问题列表。编辑代码后,我一直在调试我的程序,并注意到以下XML是我返回到streamreader中的全部内容: <feed xml:base="https://thomasmorestudent17.sharepoint.com/sites/devtest/_api/" xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://s

我们正在尝试使用c#从下面列表的条目中获取Url

编辑:

使用Alex Thompson提供的解决方案,我们能够缩小问题列表。编辑代码后,我一直在调试我的程序,并注意到以下XML是我返回到streamreader中的全部内容:

<feed xml:base="https://thomasmorestudent17.sharepoint.com/sites/devtest/_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>273fa8b2-b789-41d0-9edf-01eb12657299</id>
  <title />
  <updated>2014-03-20T09:58:18Z</updated>
  <author>
    <name />
  </author>
</feed>

273fa8b2-b789-41d0-9edf-01eb12657299
2014-03-20T09:58:18Z

这无疑不是它应该返回的XML。如果有人能为我指出这个问题的原因,我将不胜感激。我

你可以这样做:

private static readonly XNamespace d = "http://schemas.microsoft.com/ado/2007/08/dataservices";
private static readonly XNamespace m = "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata";

...

XDocument doc = XDocument.Load(itemReader.ReadToEnd());
var itemsList = doc.Descendants(m + "properties").Descendants(d + "Url").Select(item => item.Value);
如果要在对象中选择多个值,可以执行以下操作:

private static readonly XNamespace d = "http://schemas.microsoft.com/ado/2007/08/dataservices";
private static readonly XNamespace m = "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata";

...

var itemsList doc.Descendants(m + "properties").Select(
    item => new Item()
    {
        Id = item.Element(d + "Id").Value,
        Name = item.Element(d + "Name").Value,
        Url = item.Element(d + "Url").Value
    });
private static readonly XNamespace d = "http://schemas.microsoft.com/ado/2007/08/dataservices";
private static readonly XNamespace m = "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata";

...

XDocument doc = XDocument.Load(itemReader.ReadToEnd());
var itemsList = doc.Descendants(m + "properties").Descendants(d + "Url").Select(item => item.Value);
private static readonly XNamespace d = "http://schemas.microsoft.com/ado/2007/08/dataservices";
private static readonly XNamespace m = "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata";

...

var itemsList doc.Descendants(m + "properties").Select(
    item => new Item()
    {
        Id = item.Element(d + "Id").Value,
        Name = item.Element(d + "Name").Value,
        Url = item.Element(d + "Url").Value
    });