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

  • Home
  • SEARCH
  • 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 712529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:51:30+00:00 2026-05-14T04:51:30+00:00

I have the following XPATH line: //det[@nItem=1]/prod/cProd That successfully selects the desired node using

  • 0

I have the following XPATH line:

//det[@nItem=”1″]/prod/cProd

That successfully selects the desired node using XPath Visualizer, where it identifies automatically the namespace, and you define in which namespace you want to select.

When I specify the namespace in C# with the following XPATH code:

"http://www.portalfiscal.inf.br/nfe//det[@nItem=\"1\"]/prod/cProd"

it gives me an XPathException:

An unhandled exception of type
‘System.Xml.XPath.XPathException’
occurred in System.Xml.dll Additional
information:
‘http://www.portalfiscal.inf.br/nfe//det%5B@nItem=“1”]/prod/cProd’
has an invalid qualified name.

(as you can see, it’s not any escape character or anything, since it gives me what i’ve tried to reach in the exception)

How do I properly select this node providing that I know the namespace with XPath ?

–[EDIT]–
The complete line where I try to read the node:

doc.XPathSelectElement("http://www.portalfiscal.inf.br/nfe//det[@nItem=\"1\"]/prod/cProd").Value;

And the XML with unnecessary things cut out:

<?xml version="1.0" encoding="utf-8"?>
<enviNFe xmlns="http://www.portalfiscal.inf.br/nfe" versao="1.10">
<idLote>1</idLote>
<NFe>
<infNFe versao="1.10" Id="NFe31100118583682000178550010000077778397333128">
<det nItem="1">
<prod>
<cProd>111</cProd>
</prod>
</det>
</infNFe>
</NFe>
</enviNFe>

(The unnecessary things cut out should not be a problem, since XPath Visualizer brought me the node with no problems at all)

  • 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-14T04:51:30+00:00Added an answer on May 14, 2026 at 4:51 am

    Since you’re not showing us neither the XML document, nor the C# code you have, I can only guess what you’re doing….

    OK, seems you’re using Linq-to-XML, so then use this code snippet here:

    // Create and load XML reader
    XmlReader reader = XmlReader.Create(new FileStream(@"D.\test.xml", FileAccess.Read));
    
    // get the root element    
    XElement root = XElement.Load(reader);
    
    
    // create instance of XML namespace manager
    XmlNamespaceManager nsmgr = new XmlNamespaceManager(reader.NameTable);
    
    // add your namespace to the manager and give it a prefix
    nsmgr.AddNamespace("ns", "http://www.portalfiscal.inf.br/nfe");
    
    XElement node = root.XPathSelectElement("//ns:det[@nItem="1"]/ns:prod/ns:cProd", nsmgr);
    .......
    

    Something along those lines. You basically have to create a XML namespace of some sort, give it a prefix, and then use that prefix in your XPath expression – not the whole namespace – just the prefix.

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

Sidebar

Related Questions

I have the following line of xml that I'm trying transform using XSLT but
I have the following line in my xml file that I am trying to
I have the following dynamically created class that is passed into the xpath function
I have the following xpath query which seems to be working but I just
I have the following html and like to know how to use xpath to
i have the following code to for xpath query... <div class=buying> <h1 class=parseasinTitle >
I have following xml: <TextWithNodes><Node id=0 />astralis<Node id=8 /> <Node id=9 />ltd<Node id=12 />
How get node value with its children nodes? For example I have following node
I have an xml node that looks like <slot highcount=20 lowcount=10 /> I've tried
I have the following XPath: //div[contains(@id, 'box')]/div/h4/small/a[contains(@href, 'google')]/@href When I try out this XPath

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.