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,
                                          pli.Elements("Author").First().Value,
                                          pli.Elements("ThumbnailPath").First().Value,
                                          pli.Elements("VideoPath").First().Value,
                                          VideoType.Remote));

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

<PlaylistItem>
    <Videos>    
        <Video ID="1">
            <Title>RNA Alissa</Title>
            <Author>ERIC Informes RNA</Author>
            <ThumbnailPath>http://cloud.er1csports.com/mobile/images/er1c_iphone_poster.png</ThumbnailPath>
            <videoPath>http://46.105.140.18/RNA/Informe_RNA-2016-12-Alissa.mp4</videoPath>
            <videoType>Remote</videoType>
        </Video>
    </Videos>
</PlaylistItem>

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

Thanks soo much in advance!

Best Answer

Answers

  • 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: https://components.xamarin.com/view/video-player#)
    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 ✭✭✭

    @Xavi22
    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.