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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:33:16+00:00 2026-06-17T09:33:16+00:00

Hi i am doing as follow XDocument xmlDoc = XDocument.Load(@F:\test2.xml); var q = from

  • 0

Hi i am doing as follow

 XDocument xmlDoc = XDocument.Load(@"F:\test2.xml");
        var q = from c in xmlDoc.Descendants("autoivr.ok")
                where c.Element("LS_CZIP4").Value == "1234"
                select new
                {
                    name = c.Element("LS_LIN").Value,
                    state = c.Element("LS_STATE").Value                        
                };

When i use
where c.attribute(“LS_CZIP4”).Value == “1234”
i get error of object reference not set but when i use c.element there is no such error.

Following is the xml i made which is actually a table in sql converted to xml file

<?xml version="1.0" standalone="yes"?>
<DocumentElement>
   <autoivr.ok>
      <LS_LIN>abc</LS_LIN>
      <LS_STATE>def</LS_STATE>
      <LS_TYPE>5</LS_TYPE>
      <LS_CZIP4>1234</LS_CZIP4>
   <priority>0</priority>
   </autoivr.ok>

Can someone let me know the problem and how can i resolve and can i work with element tag only instead of attribute . Thank You

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

    Use casting instead of accessing Value property. Casting to string will return null for non-existing elements. Getting Value will throw an exception

    XDocument xmlDoc = XDocument.Load(@"F:\test2.xml");
    var q = from c in xmlDoc.Descendants("autoivr.ok")
            where (string)c.Element("LS_CZIP4") == "1234"
            select new
            {
                name = (string)c.Element("LS_LIN"),
                state = (string)c.Element("LS_STATE")
            };
    

    BTW you need closing tag for <DocumentElement>. Also LS_CZIP4 is element, not attribute. See the difference here XML Elements vs. Attributes.

    Element: <LS_LIN>abc</LS_LIN>

    Attribute: <autoivr.ok LS_LIN="abc">

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

Sidebar

Related Questions

i need to alert entered textbox value so i am doing it as follow.
Right now I'm doing as follow: uint8_t ManualFlow = 40; // 0 -> 255
Can someone follow what doing, and show me how to do it correctly? I'm
This is like a follow-up question to this one . Basically what I'm doing
Just a follow up from a previous question. I've got the following form.. <body
I have an XML document that I am parsing that does not follow any
I have been doing some research on the correct procedure to follow when working
I'm doing a HQL query as follows, and try to order the list by
I am doing an iPad application. MY UIView will be as follows. there will
Doing the getting started of Sinatra. I get this error: ./sinatra.rb:5: undefined method `get'

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.