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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:08:18+00:00 2026-06-10T18:08:18+00:00

I am just starting with xquery and currently I don’t know, why the following

  • 0

I am just starting with xquery and currently I don’t know, why the following is not working. I’ve created two XML files, they are identically, except that one has namespaces and the other doesn’t:

<Envelope>
    <Header>
        <JustAValue>12345</JustAValue>
    </Header>
    <Body>
        <someBody>
            <ValueIWant>12345678910</ValueIWant>
        </someBody>
    </Body>
</Envelope>


<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>
    <env:Header xmlns:wsa='http://www.w3.org/2005/08/addressing'>
        <JustAValue>12345</JustAValue>
    </env:Header>
    <env:Body xmlns:wsu='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd' wsu:Id='element-28-1344266615792-223644235'>
        <ns1:someBody xmlns='http://someURL.com' xmlns:ns1='http://someURL.com'>
            <ValueIWant>12345678910</ValueIWant>
        </ns1:someBody>
    </env:Body>
</env:Envelope>

Both xml files are in a xml field in the database.

Now I try to get the “ValueIWant” and I do it like this:

DECLARE @xml xml

Select @xml = completexml from MyDB.dbo.Xml where PKxml = 3 -- XML without namespaces

declare @somevalue nvarchar(max)

set @somevalue = @xml.value('(/Envelope/Body/someBody/ValueIWant/text())[1]', 'nvarchar(max)');

select @somevalue -- -> 12345678910


Select @xml = completexml from MyDB.dbo.Xml where PKxml = 2 -- XML with namespaces

set @somevalue = @xml.value('
declare namespace env="http://schemas.xmlsoap.org/soap/envelope/"; 
declare namespace ns1="http://someURL.com"; 
(/env:Envelope/env:Body/ns1:someBody/ValueIWant/text())[1]', 'nvarchar(max)');

select @somevalue -- -> NULL

What am I doing wrong here?

I’ve played around a bit with the XML:

<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>
    <env:Header xmlns:wsa='http://www.w3.org/2005/08/addressing'>
        <JustAValue>12345</JustAValue>
    </env:Header>
    <env:Body xmlns:wsu='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd' wsu:Id='element-28-1344266615792-223644235'>
        <ns1:someBody xmlns='http://someURL.com' xmlns:ns1='http://someURL.com'>
            <ValueIWant>12345678910</ValueIWant>
        </ns1:someBody>
        <BodyValue>BodyValue</BodyValue>
        <env:BodyValue>BodyValue</env:BodyValue>
    </env:Body>
    <env:TestValue1>TestValue</env:TestValue1>
    <TestValue2>TestValue2</TestValue2>
</env:Envelope>

I can get all the values: BodyValue, TestValue1 and TestValue2. No problem at all, but as soon as I want to change into the ns1 namespace and get ValueIWant, it just returns NULL.

  • 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-06-10T18:08:19+00:00Added an answer on June 10, 2026 at 6:08 pm

    The ValueIWant element tag name is in the default namespace (http://someURL.com), because this namespace is bound to the empty prefix by its parent element:

    <ns1:someBody xmlns='http://someURL.com' ...
    

    However in the query there seems to be no default namespace, so that the name test ValueIWant does not match the ValueIWant tag.

    Since it is the same URL that is bound to the ns1 prefix, perhaps prefixing ValueIWant with ns1 in your XPath expression would solve the problem?

    Alternatively, you could add a

    declare default element namespace "http://someURL.com";
    

    in your query. But using the ns1 prefix should normally work as well, because when comparing names (“QNames”), only the namespace and the local name matter, the prefix is irrelevant.

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

Sidebar

Related Questions

I've just starting out with obj-c and I created 2 files, a .h and
I just starting to use Visual Studio 2010 and .NET 4.0. I created a
Just starting out to program in python and I'm having the following issue. I
Just starting up with iPhone development. I'm not sure why this code works. I've
Just starting out in asp.net. Have just created a login.aspx page in my site
I am just starting to learn javascript, so I don't have the skills to
Just starting getting into Entity Framework and Linq for EF. I'm not sure which
Just starting programming, so don`t kick too hard, question is pretty self explanatory, but
Just starting with Modelica and having trouble understanding how it works. In the below
Just starting out in python on a pendrive 12.04 Kubuntu environment. I had to

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.