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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:29:15+00:00 2026-05-23T17:29:15+00:00

I need to read an xml element which has attribute xmlns=http://www.w3.org/2000/09/xmldsig#. XPathSelectElement is giving

  • 0

I need to read an xml element which has attribute xmlns=”http://www.w3.org/2000/09/xmldsig#”.
XPathSelectElement is giving error “Object reference not set to an instance of an object.”

Here is the sample code.

var xml = "<root><tagA>Tag A</tagA><tagB>Tag B</tagB></root>";
XDocument xd = XDocument.Parse(xml);
var str = xd.XPathSelectElement("/root/tagB").ToString(SaveOptions.DisableFormatting);
Console.WriteLine(str);

The result of the above code is:

<tagB>Tag B</tagB>

If I put attribute,

var xml = "<root><tagA>Tag A</tagA><tagB xmlns=\"http://www.w3.org/2000/09/xmldsig#\">Tag B</tagB></root>";

I got error.

Object reference not set to an instance of an object.

Am I missing something here? Can anyone please help me out. (I know I can get by using other methods. I just want to know what I am missing here)

Thank you very much.

  • 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-23T17:29:15+00:00Added an answer on May 23, 2026 at 5:29 pm

    You can register the element’s namespace in an XmlNamespaceManager:

    XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());
    nsmgr.AddNamespace("ns", "http://www.w3.org/2000/09/xmldsig#");
    
    var str = xd.XPathSelectElement("/root/ns:tagB", nsmgr)
                .ToString(SaveOptions.DisableFormatting);
    Console.WriteLine(str);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to read from an XML document which is alreay working. But now
<?xml version=1.0 encoding=UTF-8?> <form:Documents xmlns:form=http://www.abbyy.com/FlexiCapture/Schemas/Export/FormData.xsd xmlns:addData=http://www.abbyy.com/FlexiCapture/Schemas/Export/AdditionalFormData.xsd> <_Document_Definition_1:_Document_Definition_1 addData:ImagePath=C:\POC\Export\Test.pdf xmlns:_Document_Definition_1=http://www.abbyy.com/FlexiCapture/Schemas/Export/Document_Definition_1.xsd> <_Page_1> <_First_Name>John</_First_Name> <_Last_Name>Doe</_Last_Name> </_Page_1> </_Document_Definition_1:_Document_Definition_1>
I need to define an XML format and then read it in ActionScript3, which
I need to read and serialize objects from and to XML, Apple's .plist format
I need to read smallish (few MB at the most, UTF-8 encoded) XML files,
I need to create XML in Perl. From what I read, XML::LibXML is great
I've an xml file (Sample.xml) which has the following structure <RootElement> <Children> <Child Name=FirstChild
I have pasted the example of what I need here : http://pastie.org/1005178 I have
I want to read the xml elements dynamically (I mean without hard-coding the element
I need to read a XML file returned from a web service. I was

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.