Forum Cross Platform with Xamarin
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

How Get Elements of XML file by name

Xavi22Xavi22 ESMember
edited January 2017 in Cross Platform with Xamarin

I have an application for iOS and Android to reproduce video through xml file from visual studio for mac, but when I try to play, I didn't have videos in the list. I have this code:

public static ObservableCollection CarregarXML(XDocument XML)
ObservableCollection oCarregarXML = null;

    IEnumerable<XElement> playList = from pli in XML.Root.Descendants()
                                     where pli.Name == "Video"
                                     select pli;
    oCarregarXML = new ObservableCollection<PlaylistItem>();
    foreach (XElement pli in playList)
        oCarregarXML.Add(new PlaylistItem(pli.Elements("Title").First().Value,

When I try to run this code to read an XML file, show an error look like below:

The code of xml is:

<?xml version="1.0" encoding="UTF-8" ?>

        <Video ID="1">
            <Title>RNA Alissa</Title>
            <Author>ERIC Informes RNA</Author>

I need help, I'm very desperate for solve this error!

Thanks soo much in advance!

Best Answer


  • Xavi22Xavi22 ESMember

    Thank you soo much! Now I'm trying this code, I hope that works! :#

  • Xavi22Xavi22 ESMember

    Sorry Stefan, but the code doesn't work I have another error:

    I attached here the complete project (The project is adaptation for:
    with my modifications. Sorry but my project is too big size (1,96 GB) I didn't have attached here.

    Do you have any onedrive or dropbox or enything like this?

  • StefaanAvonds.3725StefaanAvonds.3725 USMember ✭✭✭

    If it is still a problem, you could use GitHub so others can take a look at it? Or is it a private project?

  • Xavi22Xavi22 ESMember

    Is a private project.

  • StefaanAvonds.3725StefaanAvonds.3725 USMember ✭✭✭

    For anyone interested: the problem was the XML-file that was formatted incorrectly.

    • "videoPath" had to be replaced with "VideoPath";
    • "videoType" had to be replaced with "VideoType";
    • The spaces in "< Title >" had to be removed.
Sign In or Register to comment.