treehouse : what would you like to learn today?
Web Design Web Development iOS Development

hi i want retrive data with image from xml file

  • Hi this is am using following code

      <?xml version="1.0" encoding="utf-8"?>
     <Peoples>
     <Person name="Raja">
      <Details>
        <detail games="Cricket">
          <event_image>
            <image  url="http://Cricket.jpeg"/>
          <event_image>
        </detail>
        <detail games="Foot Ball">
         <event_image>
           <image  url="http://FootBall.jpeg"/>
         <event_image>
        </detail>
        <detail games="Volley Ball">
         <event_image>
          <image  url="http://.Volley.jpeg3"/>
         <event_image>
        </detail>
     </Details>
     </Person>
    <Person name="Rama">
     <Details>
      <detail games="Chess">
        <event_image>
          <image  url="http://Chess.jpeg"/1>
          <event_image>
           </detail>
         <detail games="Table Tennis">
         <event_image>
          <image  url="http://TTennis.jpeg"/>
          <event_image>
           </detail>
      <detail games="Carrom">
        <event_image>
          <image  url="http://Carrom.jpeg"/>
          <event_image>
           </detail>
       </Details>
          </Person>
         <Peoples>  
    
    var query =from l in xmlDoc.Descendants("Person")
                               select new Notch
                               {
                                   name = (string)l.Attribute("name"),
                                   Detail = l.Element("Details")
                                             .Elements("detail").Select(x => x.Attribute("games").ToString()).ToList()
                                   Image = l.Element("Details")
                                             .Elements("detail")
                                             .Elements("event_image")
                                             .Elements("image")
                                             .Select(x => x.Attribute("url").ToString()).ToList()
                               };
                                foreach (var category in query)
                                {
                                    Console.WriteLine(category);
                                }
    
                    NotchsList.ItemsSource = query.ToList();
    

    I using this code but i got output like

     Raja
    
     System.Collection.Generic.List'1[System.String]
    
     System.Collection.Generic.List'1[System.String]
    
     Rama
    
     System.Collection.Generic.List'1[System.String]
    
      System.Collection.Generic.List'1[System.String] 
    
  • Hi WPhone7!

    First off that is not valid XML. There are neither event_image nor Peoples closing tags. And one image tag has a 1 stuck at the end: <image url="http://Chess.jpeg"/1>.

    Secondly, I think you're asking a c# question in forums that only has categories for php, css and javascript. You might get help from someone that knows c# over on StackOverflow.

    I would help, but I have no clue.