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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:04:32+00:00 2026-06-08T06:04:32+00:00

I have an xml as follows <Students xmlns=http://AdapterTest> <Schema name=Schema1 xmlns=urn:schemas-microsoft-com:xml-data xmlns:dt=urn:schemas-microsoft-com:datatypes> <ElementType name=Student

  • 0

I have an xml as follows

<Students xmlns="http://AdapterTest">
<Schema name="Schema1" xmlns="urn:schemas-microsoft-com:xml-data" xmlns:dt="urn:schemas-microsoft-com:datatypes">
    <ElementType name="Student" content="empty" model="closed">
        <AttributeType name="Student_id" dt:type="string"/>
        <AttributeType name="Student_Name" dt:type="string"/>
        <attribute type="Student_id"/>
        <attribute type="Student_Name"/>
    </ElementType>
</Schema>
<Student Student_id="123456" Student_Name="Udaya" xmlns="x-schema:#Schema1"/>
<Student Student_id="568923" Student_Name="Christie" xmlns="x-schema:#Schema1"/>
<Student Student_id="741852" Student_Name="Test Name" xmlns="x-schema:#Schema1"/>
<Student Student_id="852789" Student_Name="Sample Name" xmlns="x-schema:#Schema1"/>
</Students>

In my application I am trying to access the nodes using LINQ as follows.

XDocument xdoc1 = XDocument.Load("Customer.xml");

        List<Student> studentList =
            (from _student in xdoc1.Element("Students").Elements("Student")
             select new Student
             {
                 firstName = _student.Attribute("Student_id").Value,
                 lastName = _student.Attribute("Student_Name").Value,


             }).ToList();

It gives me an Object reference not set to an instance of an object.When I remove the xmlns=”http://AdapterTest&#8221; from the root element it works fine. What I am missing here

  • 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-08T06:04:33+00:00Added an answer on June 8, 2026 at 6:04 am

    Ive had a similar problem before like this. Like you said if you remove the namespace from the xml it works. You have to do something like this:

    XNamespace rootNs = xdoc1.Root.Name.Namespace;
    XNamespace studentNS = "x-schema:#Schema1";
    

    And then when selecting nodes prepend the selector with ns, like:

    var yourStudentList = xdoc1.Element(rootNS + "Student").Elements(studentNS + "Student");
    

    I havent tested this but it looks similar to and issue i have had.

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

Sidebar

Related Questions

Ok I have declared my main.xml as follows <?xml version=1.0 encoding=utf-8?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=wrap_content
I have got my main.xml as follows: <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:orientation=vertical android:layout_width=fill_parent
I have an XML configuration as follows: <beans xmlns=http://www.springframework.org/schema/beans xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:aop=http://www.springframework.org/schema/aop xmlns:tx=http://www.springframework.org/schema/tx xmlns:context=http://www.springframework.org/schema/context xsi:schemaLocation=
i have a XML file as follows: <?xml version=1.0 encoding=utf-8 ?> <publisher> <name>abc</name> <link>http://</link>
I have an XML string as follows: <?xml version=1.0 encoding=utf-8?> <document id=0 name=RegSimple Version=0.1>
I have an XML document as follows: <directory> <file><monitored>0</monitored> <xferStatus>1</xferStatus> <name>test1.txt</name> <size>7</size> <created>03/31/10 11:30:02
I have my XML File as follows: <states> <state name =Alaska> <Location Name=loc1> <Address>testadd1</Address>
I have a set of XML as follows: ...<spotTerms> <terms xmlns= > <term tag=1m
I have an XML schema that looks as follows: <xml> <user id=1> <first_name>Bill</first_name> <last_name>Steve</last_name>
I have specified my JAX-RS Application in the web.xml as follows: <servlet> <servlet-name>CXFServlet</servlet-name> <servlet-class>

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.