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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:12:23+00:00 2026-05-26T03:12:23+00:00

<?xml version=1.0 encoding=utf-8?> <Report p1:schemaLocation=TemplateXXX http://localhost?language=en Name=TemplateXXX xmlns:p1=http://www.w3.org/2001/XMLSchema-instance xmlns=TemplateXXX> <HEADER attr1=one attr2=two /> <Table

  • 0
<?xml version="1.0" encoding="utf-8"?> 
<Report p1:schemaLocation="TemplateXXX http://localhost?language=en" Name="TemplateXXX" xmlns:p1="http://www.w3.org/2001/XMLSchema-instance" xmlns="TemplateXXX"> 
   <HEADER attr1="one" attr2="two" /> 
   <Table filename="12345.pdf"> 
      <left> 
         <details> 
            <item/> 
            <item/> 
         </details> 
      </left> 
      <right> 
         <details> 
            <item/> 
            <item/> 
         </details> 
      </right> 
   </Table> 
</Report> 

I’m running into a strange problem when trying to query elements and attributes in an xml document where a namespace is in the xml.

When I try to query the document to get the header element with the following xpath query I consistantly get null results

XDocument root = XDocument.Load(filePath);
var element = root.XPathSelectElement("/Report/HEADER");

This always returns null however the moment I remove the namespace from the document the query returns the exepcted element.

What is it that I’m getting wrong as I’m getting some what frustrated.

edit: updated xml to valid xml

  • 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-26T03:12:24+00:00Added an answer on May 26, 2026 at 3:12 am

    I would personally recommend that you didn’t do this with XPath, but you can if you really want. Here’s a short but complete program which works with your sample XML, after I’d fixed it up (it isn’t valid XML at the moment… please try to provide working examples next time):

    using System;
    using System.Xml;
    using System.Xml.Linq;
    using System.Xml.XPath;
    
    class Test
    {
        static void Main()
        {
            var doc = XDocument.Load("test.xml");
            var manager = new XmlNamespaceManager(new NameTable());
            manager.AddNamespace("foo", "TemplateXXX");
    
            var query = doc.XPathSelectElement("/foo:Report/foo:HEADER", manager);
            Console.WriteLine(query);
        }
    }
    

    In a normal LINQ to XML query you’d just use:

    XNamespace ns = "TemplateXXX";
    XElement header = doc.RootElement.Element(ns + "HEADER");
    

    No need for a namespace manager etc.

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

Sidebar

Related Questions

I have the following XML Document: <?xml version=\1.0\ encoding=\UTF-8\?> <atom:entry xmlns:atom=\http://www.w3.org/2005/Atom\ xmlns:apps=\http://schemas.google.com/apps/2006\ xmlns:gd=\http://schemas.google.com/g/2005\> <apps:property
Here's the XML: <?xml version='1.0' encoding='UTF-8' standalone='yes' ?> <feed xmlns=http://www.w3.org/2005/Atom xmlns:dc=http://purl.org/dc/elements/1.1/> <title>Rated Images</title> <link
I have the following XML document <?xml version='1.0' encoding='UTF-8'?><entry xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' xmlns:issues='http://schemas.google.com/projecthosting/issues/2009' gd:etag='W/DEAERH47eCl7ImA9WhZTFEQ.'><id>http://code.google.com/feeds/issues/p/chromium/issues/full/921</id><published>2008-09-03T22:51:22.000Z</published><updated>2011-03-19T01:05:05.000Z</updated><title>Incorrect rendering</title><content
The following .jrxml: <?xml version=1.0 encoding=UTF-8?> <jasperReport xmlns=http://jasperreports.sourceforge.net/jasperreports xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:schemaLocation=http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd name=DTC-Campaigns-Block-Campaigns-Helper-Campaigns language=groovy pageWidth=794
Given below is my xml: <?xml version=1.0 encoding=utf-8?> <Report xmlns:rd=http://schemas.microsoft.com/SQLServer/reporting/reportdesigner xmlns=http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition> <Body> <ReportItems> <Textbox
<?xml version=1.0 encoding=utf-8?> <Report p1:schemaLocation=Customer details http://reportserver?%2fCustomer details&amp;rs%3aFormat=XML&amp;rc%3aSchema=True Name=Customer details xmlns:p1=http://www.w3.org/2001/XMLSchema-instance xmlns=Customer details> <table2>
<?xml version=1.0 encoding=utf-8 ?> <reportgroups> <Reportgroup id=1 name=reportGroup1> <report id=1 name=report1 isSheduled=false></report> <report id=2
My select_screen_menu.xml <?xml version=1.0 encoding=utf-8?> <menu xmlns:android=http://schemas.android.com/apk/res/android> <item android:id=@+id/home_menu android:icon=@drawable/home_tab android:title=Home /> <item android:id=@+id/submit_report
`** <?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 android:layout_height=fill_parent android:weightSum=1> <TextView android:layout_width=fill_parent android:layout_height=wrap_content android:text=Excel
I have an XML file that looks like <?xml version='1.0' encoding='UTF-8'?> <root> <node name=foo1

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.