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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:58:37+00:00 2026-05-26T14:58:37+00:00

I have a XPath expression that is supposed to return/get only one node out

  • 0

I have a XPath expression that is supposed to return/get only one node out of the XML document. But it is getting more than the one. I don’t understand why.

Code-behind:

Dim xmlNameTbl As XmlNameTable = rootDoc.NameTable
Dim xmlNS As XmlNamespaceManager = New XmlNamespaceManager(xmlNameTbl)
xmlNS.AddNamespace("asp", "http://test.com/asp")

Dim sectionPosition As String = rowNode.GetAttribute("ID")
'In this example sectionPosition is "A03"

Dim sectionLetter As String = rowNode.GetAttribute("ID").Substring(0, 1)
Dim sectionRowNumberText As String = rowNode.GetAttribute("ID").Remove(0, 1)
Dim sectionRowNumber As Integer
Integer.TryParse(sectionRowNumberText, sectionRowNumber)

Dim addingNav As XPathNavigator = rootDoc.CreateNavigator

Dim hello = rootDoc.ChildNodes

Dim addingItr As XPathNodeIterator = addingNav.Select("//asp:TableRow[@ID='" & sectionPosition & "']", xmlNS)
'Nodes with A03 and A02 are being returned, even though it should be only A03 returned

XML Document:

<?xml version="1.0" encoding="utf-8"?>
<Root xmlns:asp="http://test.com/asp" xmlns:meta="http://test.com/meta" xmlns:cc1="http://test.com/cc1">
  <asp:TableRow ID="A03">
    <asp:TableCell>
      <asp:Localize ID="tagthreeCtrlNumberRes" meta:resourcekey="tagthreeCtrlNumberRes" runat="server" />
    </asp:TableCell>
    <asp:TableCell>
      <asp:Localize ID="tagthreeCtrlDescRes" meta:resourcekey="tagthreeCtrlDescRes" runat="server" />
      <asp:Localize ID="tagthreeCtrlNoteRes" meta:resourcekey="tagthreeCtrlNoteRes" runat="server" />
    </asp:TableCell>
    <asp:TableCell>
      <asp:RadioButtonList ID="rblthreeCtrlRes0" RepeatDirection="Horizontal" runat="server">
        <asp:ListItem Text="Yes" meta:resourcekey="rblthreeCtrl0Res0" Value="1" />
        <asp:ListItem Text="No" meta:resourcekey="rblthreeCtrl1Res0" Value="0" />
        <asp:ListItem Text="N/A" meta:resourcekey="rblthreeCtrl2Res0" Value="2" />
      </asp:RadioButtonList>
      <asp:RadioButtonList ID="rblthreeCtrlRes1" RepeatDirection="Horizontal" runat="server">
        <asp:ListItem Text="Yes" meta:resourcekey="rblthreeCtrl0Res1" Value="1" />
        <asp:ListItem Text="No" meta:resourcekey="rblthreeCtrl1Res1" Value="0" />
        <asp:ListItem Text="N/A" meta:resourcekey="rblthreeCtrl2Res1" Value="2" />
      </asp:RadioButtonList>
    </asp:TableCell>
    <asp:TableCell>
      <asp:Button ID="cmdthreeCtrlRes" meta:resourcekey="cmdthreeCtrlRes" runat="server" OnClick="FormDataSave_Click" />
    </asp:TableCell>
    <asp:TableCell>
      <asp:Localize ID="lblAssmthreeCtrlRes" meta:resourcekey="lblAssmthreeCtrlRes" runat="server" />
    </asp:TableCell>
    <asp:TableCell>
      <asp:Localize ID="lblQualthreeCtrlRes" meta:resourcekey="lblQualthreeCtrlRes" runat="server" />
      <asp:Button ID="cmdQualAcceptthreeCtrlRes" meta:resourcekey="cmdQualAcceptthreeCtrlRes" OnClick="cmdQualAccept_Click" runat="server" Text="Accept" Visible="True" />
    </asp:TableCell>
    <asp:TableCell />
    <asp:TableCell />
  </asp:TableRow>
  <asp:TableRow ID="A04">
    <asp:TableCell>
      <asp:Localize ID="tagoneCtrlNumberRes" meta:resourcekey="tagoneCtrlNumberRes" runat="server" />
    </asp:TableCell>
    <asp:TableCell>
      <asp:Localize ID="tagoneCtrlDescRes" meta:resourcekey="tagoneCtrlDescRes" runat="server" />
      <asp:Localize ID="tagoneCtrlNoteRes" meta:resourcekey="tagoneCtrlNoteRes" runat="server" />
    </asp:TableCell>
    <asp:TableCell>
      <asp:Localize ID="tagtxtoneCtrlRes0" meta:resourcekey="tagtxtoneCtrlRes0" runat="server" />
      <asp:Textbox ID="txtoneCtrlRes0" runat="server" />
    </asp:TableCell>
    <asp:TableCell>
      <asp:Button ID="cmdoneCtrlRes" meta:resourcekey="cmdoneCtrlRes" runat="server" OnClick="FormDataSave_Click" />
    </asp:TableCell>
    <asp:TableCell>
      <asp:Localize ID="lblAssmoneCtrlRes" meta:resourcekey="lblAssmoneCtrlRes" runat="server" />
    </asp:TableCell>
    <asp:TableCell />
    <asp:TableCell />
    <asp:TableCell />
  </asp:TableRow>
  <asp:TableRow ID="A02">
    <asp:TableCell>
      <asp:Localize ID="tagtwoCtrlNumberRes" meta:resourcekey="tagtwoCtrlNumberRes" runat="server" />
    </asp:TableCell>
    <asp:TableCell>
      <asp:Localize ID="tagtwoCtrlDescRes" meta:resourcekey="tagtwoCtrlDescRes" runat="server" />
      <asp:Localize ID="tagtwoCtrlNoteRes" meta:resourcekey="tagtwoCtrlNoteRes" runat="server" />
    </asp:TableCell>
    <asp:TableCell>
      <asp:Localize ID="tagtxttwoCtrlRes0" meta:resourcekey="tagtxttwoCtrlRes0" runat="server" />
      <asp:Textbox ID="txttwoCtrlRes0" runat="server" />
    </asp:TableCell>
    <asp:TableCell>
      <asp:Button ID="cmdtwoCtrlRes" meta:resourcekey="cmdtwoCtrlRes" runat="server" OnClick="FormDataSave_Click" />
    </asp:TableCell>
    <asp:TableCell>
      <asp:Localize ID="lblAssmtwoCtrlRes" meta:resourcekey="lblAssmtwoCtrlRes" runat="server" />
    </asp:TableCell>
    <asp:TableCell />
    <asp:TableCell />
    <asp:TableCell />
  </asp:TableRow>
</Root>
  • 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-26T14:58:38+00:00Added an answer on May 26, 2026 at 2:58 pm

    I cannot find anything wrong with the above code/XML.

    Running your example works as expected, with addingItr.Count returning 1.

    I double checked this by iterating the returned nodes like so:

    For Each n As XPathNavigator In addingItr
        Dim nodeName As String = n.Name
    Next
    

    What code are you running to determine the count of the returned nodes?

    Edit

    From: XPathNodeIterator Class

    An XPathNodeIterator object returned by the XPathNavigator class is
    not positioned on the first node in a selected set of nodes. A call to
    the MoveNext method of the XPathNodeIterator class must be made to
    position the XPathNodeIterator object on the first node in the
    selected set of nodes.

    So what you are seeing when debugging is the InnerXml property of the root node.

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

Sidebar

Related Questions

I have the following XPATH line: //det[@nItem=1]/prod/cProd That successfully selects the desired node using
Is it possible to use XPath to select only the nodes that have a
I have code that I expect to return the element name, but nothing is
I have an xml node that looks like <slot highcount=20 lowcount=10 /> I've tried
I have a xpath expression that returns a list of urls that are in
I'm trying to get an XPath expression together that will give me all the
You can verify an XPath expression against an XML doc to verify it, but
So I have some perl code that goes something like: use strict; use XML::XPath;
I have this xpath expression that does not work //div[child[0]::h4[text()[contains(.,'Dir')]]]/a To parse this html:
I'm attempting to create an xquery expression that will return selected nodes but will

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.