Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

Is it wrong? Please suggest me correct way.

Public Function ReadXML() As Lis<small>t(Of String)
        Dim list As New List(Of String)
        Dim xmlDoc As XDocument = XDocument.Load("C:\\MappingFile.xml")
        Dim q = From c In xmlDoc.Descendants("Entity") Where c.Attribute("Source").Value = "E_cdclient"
                 Select New With {
                     .source = c.Elements("Property").Attributes("Source"),  //This is one collection
             .target = c.Elements("Property").Attributes("Target")   //This is another collection.
                 }
        list = q    //Here I am getting error.
        Return list
End Function
</small>

Here is my XML.
<?xml version="1.0" encoding="utf-8" ?>
<Entities>
  <Entity Source="E_cdclient" Target="cd_client">
    <Property Source="KnowledgeItemId" Target="CLIENT_CONTACT_ID"/>
    <Property Source="KnowledgeClientID" Target="CLIENT_CONTACT_ID"/>
  </Entity>
  <Entity Source="E_cdclientsystem" Target="cd_client_system">
    <Property Source="PrimaryKnowledgeItemId" Target="0"/>
    <Property Source="RelatedKnowledgeId" Target="0"/>
  </Entity>
  <Entity Source="E_cdclient_cdclientcontact" Target="cd_client_contact">
    <Property Source="shortdescription" Target="analysis_short_description"/>
    <Property Source="OWNERID" Target="REF_PROJECT_OWNER_ID"/>
  </Entity>
  <Entity Source="E_cdclient_cdquestiontype" Target="cd_questiontype">
    <Property Source="" Target="analysis_short"/>
    <Property Source="" Target="analysis_sho"/>
  </Entity>
</Entities>

Thanks,
JN
Posted
Updated 6-Jul-11 5:11am
v2
Comments
R. Giskard Reventlov 6-Jul-11 11:11am    
You need to tell us what errors or result you are getting.

1 solution

Yes it is wrong. The projections is formed as an IEnumerable and must be cast to a List with the ToList method. Also your projection is an object composed of two collections, not a string.

LINQ to XML[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900