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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:50:13+00:00 2026-05-26T00:50:13+00:00

Is anyone able to explain why the two results are different, even though the

  • 0

Is anyone able to explain why the two results are different, even though the node XML representation is exactly the same?

declare @t varchar(max) set @t = '<a><b><c/></b><d>eeee</d></a>'
declare @x xml set @x = cast(@t as xml)
select N.query('.'), N.value('local-name(.)','varchar(max)')+'.' from @x.nodes('//*') T(N)
select N.query('.'), N.value('local-name(.)','varchar(max)')+'.' from @x.nodes('/') T(N)

Result1:

Col1                              Col2
<a><b><c /></b><d>eeee</d></a>    a.
<b><c /></b>                      b.
<c />                             c.
<d>eeee</d>                       d.

Result2:

Col1                              Col2
<a><b><c /></b><d>eeee</d></a>    .

Answer: (with the help from accepted answer from Mitch)

This query more clearly (relatively speaking) shows what is happening:

declare @t varchar(max) set @t = '<a><b><c/></b><d>eeee</d></a><x />'
declare @x xml set @x = cast(@t as xml)
select N.query('.'), N.value('local-name(.)','varchar(max)')+'.' from @x.nodes('//*') T(N)
select N.query('.'), N.value('local-name(.)','varchar(max)')+'.' from @x.nodes('/*') T(N)
select N.query('.'), N.value('local-name(.)','varchar(max)')+'.' from @x.nodes('/') T(N)

Result1:

Col1                              Col2
<a><b><c /></b><d>eeee</d></a>    a.
<b><c /></b>                      b.
<c />                             c.
<d>eeee</d>                       d.

Result2:

Col1                              Col2
<a><b><c /></b><d>eeee</d></a>    a.
<x />                             x.

Result3:

Col1                                  Col2
<a><b><c /></b><d>eeee</d></a><x />   .

So in the original question, even though the XML in the results 1 and 2 are identical visually, they are "different".

  1. The first one is the XML-node starting at taking the (virtual) position of "root"
  2. The second one has a "virtual root" that is a "document" element that is not visually displayed.
  • 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-26T00:50:14+00:00Added an answer on May 26, 2026 at 12:50 am

    '/' Selects from the root node

    '//' Selects nodes in the document from the current node that match the selection no matter where they are.

    Query 1 matches all root elements.

    Query 2 matches the single element at the document root. The document root does not have a name.

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

Sidebar

Related Questions

I'm confused by these two warnings. Can anyone explain how I might have come
I was wondering if anyone might be able to explain to me why it's
Anyone able to explain what | and the value after does? I know the
http://www.liveprofile.com/ I was wondering if anyone would be able to explain roughly how an
Is there anyone able to explain me this strange behavior? int i = 0x1234;
Would anyone be able to explain to me what data encapsulation in Objective-C is?
anyone able to tell me how often a materialized view is set to refresh
Has anyone been able to get an NHibernate-based project up and running on a
Has anyone been able to get xinc to run correctly under OpenBSD's chrooted default
Has anyone been able to get a variable record length text file (CSV) into

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.