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 3219708
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:40:39+00:00 2026-05-17T15:40:39+00:00

I’m trying to write a windows phone 7 app which reads from an xml

  • 0

I’m trying to write a windows phone 7 app which reads from an xml using xdocument but i’m having a few problems.

If I do this:

Dim xml As XDocument = XDocument.Load(e.Result)
System.Diagnostics.Debug.WriteLine(xml.ToString)

Or this:

System.Diagnostics.Debug.WriteLine(xml.Elements.Value.ToString)

then the xml data is output to the immidiate window as a string proving that the data exists but if i do this:

Dim products = From product In xml.Descendants("product") _
                    Select title = product.Element("title").Value

For Each product In products
     System.Diagnostics.Debug.WriteLine("Title" & product.title)
Next

I get nothing for product.title and I also get nothing when I do stuff like this:

Dim count As Integer = xml.Descendants("count").Value

What am I doing wrong?
Thanks.

xml looks something like this:

<productslist>
  <count>2</count>
  <products>
    <product>
        <productId>1</productId>
        <title>test item 1 </title>
        <price>4.99</price>
        <category>
            <categoryId>1</categoryId>
            <categoryName>cat 1</categoryName>
        </category>
    </product>
    <product>
        <productId>2</productId>
        <title>test item 2</title>
        <price>10.99</price>
        <category>
            <categoryId>2</categoryId>
            <categoryName>cat 2</categoryName>
        </category>
    </product>
 </productslist>
  • 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-05-17T15:40:40+00:00Added an answer on May 17, 2026 at 3:40 pm

    Your LINQ statement is not projecting into an anonymous type with a property of Title. You’re getting an IEnumerable<string> back directly.

    Try this instead:

    Dim products = From product In xml.Descendants("product") _
                   Select product.Element("title").Value
    
    For Each product In products
         Debug.WriteLine("Title: " & product)
    Next
    

    That said, the variable products is better named titles. If you want to project into an anonymous type you need to use With New { .Prop1 = data, .Prop2 = other }. A dot must be prefixed to each property name. Here’s an example:

    Dim products = From product In xml.Descendants("product") _
                   Select New With { .Title = product.Element("title").Value }
    
    For Each product In products
         Debug.WriteLine("Title: " & product.Title)
    Next
    

    For your example it doesn’t seem that an anonymous type is needed. If you have multiple properties to project into then it becomes worthwhile.

    EDIT: in response to your comment, a namespace might be attached to your XML. If so, you would need to reference it to reference any element.

    If your XML has a namespace it should have an xmlns specified, such as:

    <productslist xmlns="http://domain.com/namespace">
    

    You would then have to modify your code to get the namespace and concatenate it with your elements as follows:

    Dim ns = xml.Root.GetDefaultNamespace()
    
    Dim products = From product In xml.Descendants(ns + "product") _
                   Select product.Element(ns + "title").Value
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.