Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

270
Views
Linq2XML can't find element with namespace

I have this XML

<SENDERS VERSION="V3.0.4" xsi:noNamespaceSchemaLocation="SENDERS.xd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <SECTION>
  </SECTION>
</SENDERS>

I am trying to parse it and find the element SECTION with the xsi namespace using the following code

var xdoc = XDocument.Parse(myxml);
var ns = xdoc.Root.GetNamespaceOfPrefix("xsi");
var section = xdoc.Element(ns + "SECTION");

Usually I do it this way but this time section is always null. Am I doing something wrong?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I think you remember it wrong. Actually the <SECTION> element does not have any explicit namespace prefix so it can only have a default namespace (which is declared without prefix).

Because your XML does not declare any default namespace (e.g: xmlns=...). So your <SECTION> has no namespace, the working code should be like this:

var section = xdoc.Root.Element("SECTION");

Another problem is you need to use XDocument.Root.Element instead of XDocument.Element.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!