0

I am working on silverlight to bind a xml file to datagrid.I have found many example but my xml file is very complex. so how to read or bind it to data grid. Below is my xml file and i want to read element "EntityType" with its sub element and its attribute values.

Thanks.

`<?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>`

1 Answer 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:..... 
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.