0

我正在使用 silverlight 将 xml 文件绑定到 datagrid。我找到了很多示例,但我的 xml 文件非常复杂。那么如何读取或将其绑定到数据网格。下面是我的 xml 文件,我想读取元素“EntityType”及其子元素及其属性值。

谢谢。

`<?xml version="1.0" encoding="utf-8" ?>
<edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx">
  <edmx:DataServices xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" m:DataServiceVersion="1.0">
    <Schema Namespace="Microsoft.Crm.Sdk.Data.Services" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://schemas.microsoft.com/ado/2007/05/edm">
      <EntityType Name="SdkMessageRequestField">
        <Key>
          <PropertyRef Name="SdkMessageRequestFieldId" />
        </Key>
        <Property Name="FieldMask" Type="Edm.Int32" Nullable="true" />
        <Property Name="Name" Type="Edm.String" Nullable="true" />
      </EntityType>
      <ComplexType Name="EntityReference">
        <Property Name="Id" Type="Edm.Guid" Nullable="true" />
        <Property Name="LogicalName" Type="Edm.String" Nullable="true" />
        <Property Name="Name" Type="Edm.String" Nullable="true" />
      </ComplexType>
    </Schema>
  </edmx:DataServices>
</edmx:Edmx>`
4

1 回答 1

1

XDocument x = XDocument.Load("XMLFileName.xml");

    var a = (from c in x.Descendants("edmx").Elements("Schema").Elements("EntityType/ComplexType") 

             select new 
             { 
                 Name = c.Parent.Attribute("Name"), 
                 PropertyName = c.Attribute("Name"),
                 PropertyType = c.Attribute("Type")
             }).ToArray(); 

    foreach (var itm in a) 
    { 
        // TODO:..... 
    }
于 2012-09-06T06:53:34.460 回答