0

xmlファイルをdatagridにバインドするためにSilverlightに取り組んでいます。多くの例を見つけましたが、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 に答える