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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:52:12+00:00 2026-06-02T18:52:12+00:00

I am trying to read some data from my XML file Names/Name/trckid 1) For

  • 0

I am trying to read some data from my XML file

Names/Name/trckid

  • 1) For example from an xml file like the one pasted below I want to
    read Names/Name/trckid
    eg :trckid= FF7eb01f7-7985-47b1-8f8c-a0e92395d00f

  • 2) as well as Names/Name/Files/file/uri where formatCode=”2001″
    eg resulting string: uri=http://cont.catalog.address.xyz.com/e2/ds/9b660964.jpg

Here is my sample XML file

<?xml version="1.0" encoding="utf-8"?>
<Names tracking="trckids" execTime="0" xmlns="urn:schemas-microsoft-com:address:catalog">
    <Name xmlns="urn:schemas-microsoft-com:address:catalog" publishState="Published" lcid="1033" options="0" version="65" filterFlags="32687">
        <trckid ref="5ofol35" seoMetaData="/xyz/gpscatalog/">FF7eb01f7-7985-47b1-8f8c-a0e92395d00f</trckid>
        <providerId>Test0_2286326_304163829</providerId>
        <files>
            <file formatCode="2001" gpsFileId="9B660964-1626-466C-8359-F036506D8769" height="102" width="136" fileHash="4a4bcceb08b4ccdd16a958e8687c9588">
                <uri>http://cont.catalog.address.xyz.com/e2/ds/9b660964-1626-466c-8359-f036506d8769.jpg</uri>
            </file>
            <file formatCode="2007">
                <uri>http://img1.catalog.address.xyz.com/image.aspx?uuid=d7eb01f7-7985-47b1-8f8c-a0e92395d00f&amp;w=136&amp;h=102</uri>
            </file>
            <file formatCode="2200" gpsFileId="6C34F723-D798-4DA8-AEE4-0442C239D3A0" fileSize="311469" height="180" width="320"                                                                             sourceFileHash="6ea74770f622e3e0dc9cf5e229c7de7f">
                <uri>http://cont.catalog.address.xyz.com/e2/ds/0909a015-4b6a-4574-be63-c2facd527b9f_0.xml</uri>
            </file>
        </files>
    </Name>
   <Name xmlns="urn:schemas-microsoft-com:address:catalog" publishState="Published" lcid="1033" options="0" version="65" filterFlags="32687">
        <trckid ref="5ofol20" seoMetaData="/xyz/gpscatalog/">FF9eb01f7-7985-47b1-8f8c-a0e92395d00f</trckid>
        <providerId>Test1TheLorax_2286326_304163829</providerId>
        <files>
            <file formatCode="2001" gpsFileId="9B660964-1626-466C-8359-F036506D8769" height="102" width="136" fileHash="4a4bcceb08b4ccdd16a958e8687c9588">
                <uri>http://cont.catalog.address.xyz.com/e2/ds/9b660964-1626-466c-8359-f036506d8769.jpg</uri>
            </file>
            <file formatCode="2007">
                <uri>http://img1.catalog.address.xyz.com/image.aspx?uuid=d7eb01f7-7985-47b1-8f8c-a0e92395d00f&amp;w=136&amp;h=102</uri>
            </file>
            <file formatCode="2200" gpsFileId="6C34F723-D798-4DA8-AEE4-0442C239D3A0" fileSize="311469" height="180" width="320"                                                                             sourceFileHash="6ea74770f622e3e0dc9cf5e229c7de7f">
                <uri>http://cont.catalog.address.xyz.com/e2/ds/0909a015-4b6a-4574-be63-c2facd527b9f_0.xml</uri>
            </file>
        </files>
    </Name>
</Names>

I tried with the below given piece of code

      XDocument xdoc = XDocument.Parse(xmlstring);
            XNamespace ns = xdoc.Root.GetDefaultNamespace();  // "urn:schemas-microsoft-com:msnvideo:catalog";
            IEnumerable<XElement> names = xdoc.Descendants(ns + "name");
   foreach (XElement name in names)
            {


                 rssFeedItems.Add(new Adressses
                    {
                    trackid=  Convert.ToString(name.Element(ns + "trackid").Value),
                    providerID= Convert.ToString(name.Element(ns + "provideid").Value),

                    imageUri = Convert.ToString(name.Element(ns + "uri").Value)
                    });

            }        
  Here  am able to read first two items ,ie, trackid and providerID ,but not the image uri

I need to read the uri that matches Names/Name/files/file@formatcode[2001]/uri

something like

 imageUri = Convert.ToString(name.Element(ns + "Names/Name/files/file@formatcode[2001]/uri").Value)

but this just doesn’t work . please 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-02T18:52:16+00:00Added an answer on June 2, 2026 at 6:52 pm

    First thing, your xml is invalid. The end tag should look like this </Names> instead of <Names/>

    Secondly, you’ve got to add the namespace declaration. Like this:

        XNamespace cat = "urn:schemas-microsoft-com:address:catalog";
        XNamespace add = "urn:schemas-microsoft-com:msnvideo:address";
        XDocument doc = XDocument.Parse(xdata);
        var firstTrck = doc.Element(cat + "Names").Elements(add + "Name").First().Element(add + "trckid");
        var val = firstTrck.Value;
    

    Also of note, careful with how you append (s) on Element/Elements to make sure you are looking for one or many elements.

    Here’s how to iterate over your element collections:

            XNamespace cat = "urn:schemas-microsoft-com:address:catalog";
            XNamespace add = "urn:schemas-microsoft-com:msnvideo:address";
            XDocument doc = XDocument.Parse(xdata);
    
            var xNames = doc.Element(cat + "Names").Elements(add + "Name");
            foreach (var xName in xNames)
            {
                var trackingId = xName.Element(add + "trckid").Value;
    
                var xFiles = xName.Element(add + "files").Elements(add + "file").Where(xe => (string)xe.Attribute("formatCode") == "2001");
                foreach (var xFile in xFiles)
                {
                    var uri = xFile.Element(add + "uri").Value;
                }
            }
    

    Notice when you debug this that only one of the “Name” elements appears in the collection. This is because the xmlns declaration doesn’t match for each.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to read in some sample data from an XML file in a
I am trying to read some data from a xml file, numbers are saved
I am trying to read some data from a python module from a web.
I'm trying to store some binary data obtained from read() in my buffer using
I am trying to read some info from a text file by using windows
Hi I am trying to read an xml file from outside the web-app container,
I am trying to read a xml file from the web and parse it
I am trying to extract some data from an XML input with 6 lines,
I am trying to load data from XML string into a structure of some
I am trying to add some data received from a form to an XML

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.