Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

274
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda