Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7757023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:58:29+00:00 2026-06-01T12:58:29+00:00

I have this simple XML file : <?xml version=1.0 encoding=utf-8 ?> <Artists> <artist artistId=1>

  • 0

I have this simple XML file :

<?xml version="1.0" encoding="utf-8" ?>
<Artists>
 <artist artistId="1">
<name>ManyBass</name>
<genre>Electronic</genre>
 <album>Fireblue</album>
 <player>
    <song path="Fireblue.mp3"/>
    <song path="Porthole.mp3"/>
</player>
 </artist>
</Artists>

I want to retrieve all song path to add it in a ListBox like this :

XDocument loaded = XDocument.Load(path);
var q = from c in loaded.Descendants("player")
        select (string)c.Element("song path");
foreach (string track in q)
{
   myList.Items.Add(track);
}

But my program crash because the track string launch a SystemNullExceptionError. Can someone help me to retrieve properly the attribute :

song path

from my XML file ? Thanks for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T12:58:30+00:00Added an answer on June 1, 2026 at 12:58 pm

    A MVVM styled approach would have you bind your ListBox directly to your XML document so that you don’t have to set the contents of the ListBox in the back code.

    XAML:

    <Grid>
        <Grid.DataContext>
            <XmlDataProvider Source="Artists.xml" XPath="/Artists/artist"/>
        </Grid.DataContext>
        <ListBox ItemsSource="{Binding}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <DockPanel>
                        <TextBlock Text="{Binding XPath=./name}" DockPanel.Dock="Left"/>
                        <ListBox ItemsSource="{Binding XPath=./player/song}" DockPanel.Dock="Right">
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding XPath=@path}"/>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                    </DockPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>      
    </Grid>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple XML file like this: <?xml version=1.0 encoding=UTF-8?> <?xml-stylesheet type=text/xsl href=01C3_OIZODEMO_certificato_v1.0.xsl?>
I have a XML file like this: <?xml version='1.0' encoding='utf-8'?> <sitegroup name = 'healthcare'>
I have a simple XML file, items.xml: <?xml version=1.0 encoding=UTF-8 ?> <items> <item> <name>mouse</name>
I have a simple xml file that looks like this: <?xml version=1.0 encoding=UTF-8 standalone=yes
I have a simple XML file like so: <?xml version=1.0 encoding=UTF-8?> <foo attr=blah &#176;
I have this XML file: <?xml version=1.0 encoding=utf-8?> <Wpf> <wpfctrl id=NavBtnTemplate>#FFCFDEFF</wpfctrl> </Wpf> and i
I have a simple XML file: <?xml version=1.0 encoding=utf-8?> <ConvenioValidacao> <convenio ven_codigo=1 tipoValidacao=CPF></convenio> <convenio
This is my xml file: <?xml version=1.0 encoding=UTF-8?> <CONTACTS> <CONTACT> <FirstName>Arun</FirstName> <LastName>Arun_Neelam</LastName> <Email>nuraaa_iceee@yahoo.co.in</Email> </CONTACT>
I have this xml result from calling the page getRout.php <?xml version=1.0 encoding=UTF-8?> <kml
I've got an app.config file, which contains the following <?xml version=1.0 encoding=utf-8 ?> <configuration>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.