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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:42:19+00:00 2026-06-09T09:42:19+00:00

im having trouble getting elements from my XML. I cannot get the Vehicles or

  • 0

im having trouble getting elements from my XML. I cannot get the Vehicles or Vehicle elements from my XML, it always returns null.

Can any one see where im going wrong?

Here is my code…

    [TestMethod]
    public void TestDeleteVehicleFromXMLFile()
    {
        using (FileStream stream = new FileStream(base._TestXPathXMLFile, FileMode.Open))
        {
            try
            {
                XDocument xDoc = XDocument.Load(stream);
                var q = from RootNode in xDoc.Descendants("VehicleCache")

                    select new
                    {
                        // Vehicles & VehiclesList is always null
                        Vehicles = RootNode.Elements(XName.Get("Vehicle")).ToList(),
                        VehiclesList = RootNode.Elements(XName.Get("Vehicles")).ToList(),
                        SelfNode = RootNode.DescendantNodesAndSelf().ToList(),
                        DescendantNodes = RootNode.DescendantNodes().ToList()
                    };

                // used to see what is in item
                foreach (var item in q)
                {
                    int i = 0;
                }
            }
            catch(Exception E)
            {
                Assert.Fail(E.Message);
            }
        }
    }


<VehicleCache>
<Vehicles xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.myURL.co.uk">
    <Vehicle>
      <CapCode>41653</CapCode>
      <TrueCap i:nil="true" />
      <VehicleID>365789</VehicleID>
      <ViperVehicleID i:nil="true" />
      <BodyTypeID>5</BodyTypeID>
    </Vehicle>
    <Vehicle>
      <CapCode>42565</CapCode>
      <TrueCap i:nil="true" />
      <VehicleID>365845</VehicleID>
      <ViperVehicleID i:nil="true" />
      <BodyTypeID>2</BodyTypeID>
    </Vehicle>
</Vehicles>

  • 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-09T09:42:20+00:00Added an answer on June 9, 2026 at 9:42 am

    Define XNamespace

    XNamespace ns = "http://www.myURL.co.uk";
    

    Use that:

    Vehicles = RootNode.Elements(XName.Get(ns + "Vehicle")).ToList(),
    

    Or if you want to avoid using Namespace then try:

    var result = xDoc.Descendants().Where(r => r.Name.LocalName == "VehicleCache");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble getting the jQuery validation plugin to validate single input elements on
im having trouble getting a string (containing a URL) from one activity to another.
I am having trouble getting dynamic content coming from a custom handler to be
I am having trouble getting a working example that reads metadata from a WebVTT
I'm having trouble getting the elements in my <div id=wrapper> to push down my
I am having trouble getting jquery to recognize an element that is created from
I'm having trouble getting post DOM created elements to inherit jquery events. As I
I'm having trouble getting IE7 to float my elements correctly (FF and Chrome work
I'm having trouble getting the right number of elements in the ArrayList alt in
Hello all having some trouble accessing elements from a returned JSON from Twitter. I'm

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.