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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:37:57+00:00 2026-06-02T20:37:57+00:00

This code works fine when you remove the <data> wrapper, from the XML and

  • 0

This code works fine when you remove the <data> wrapper, from the XML and the nodes, but when you add it, like below, i get 0 results.

  -- Declare XML variable
  DECLARE @data XML;

  -- Element-centered XML
  SET @data =
  N'
  <data xmlns="test.xsd">
    <subdata>
      <customer>
        <id>1</id>
        <name>Allied Industries</name>
      </customer>
      <customer>
        <id>2</id>
        <name>Trades International</name>
      </customer>
    </subdata>
  </data>';

  -- Using the query() method
  SELECT T.customer.query('id').value('.', 'INT') AS customer_id,
         T.customer.query('name').value('.', 'VARCHAR(20)') AS customer_name
  FROM @data.nodes('data/subdata/customer') AS T(customer);

But works fine when i do it like this:

  -- Element-centered XML
  SET @data =
  N'
    <subdata>
      <customer>
        <id>1</id>
        <name>Allied Industries</name>
      </customer>
      <customer>
        <id>2</id>
        <name>Trades International</name>
      </customer>
    </subdata>
 ';

  -- Using the query() method
  SELECT T.customer.query('id').value('.', 'INT') AS customer_id,
         T.customer.query('name').value('.', 'VARCHAR(20)') AS customer_name
  FROM @data.nodes('subdata/customer') AS T(customer);

Does anyone know how or why I’m not getting results in the first example, when the <data> parent wrapper is there?

  • 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-02T20:37:59+00:00Added an answer on June 2, 2026 at 8:37 pm

    The problem has nothing to do with the number of “wrappers” around your XML data. The issue is: your first sample defines an XML namespace (xmlns="test.xsd") on the <data> node, but your query isn’t respecting that.

    You need to change your query to be something like this:

    -- Using the query() method
    ;WITH XMLNAMESPACES (DEFAULT 'test.xsd')
    SELECT 
        T.customer.query('id').value('.', 'INT') AS customer_id,
        T.customer.query('name').value('.', 'VARCHAR(20)') AS customer_name
    FROM 
        @data.nodes('data/subdata/customer') AS T(customer);
    

    Then you’ll get results….

    Without this XML namespace declaration, your query would work just fine – two wrappers or more doesn’t matter at all..

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

Sidebar

Related Questions

This code works fine for FF, Safari, Chrome and IE9, but doesn't work 100%
This code works fine in <= IE7, but it doesn't work in firefox ..
This code works fine to find an available room within certain date, but it
This code works fine in C#: Expression.Lambda(LambdaBody); But none of the methods for building
The code below is creating a server to communicate with clients.This code works fine
I have this code that works fine when I call it from within the
This code works fine to create a grid of divs: for (var i =
this code works fine until I start scrolling: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
web page : http://sideradesign.com/eco-art/gallery/ This code works fine in all brwosers except IE8 (haven't
this jquery code works fine for me in jquery format. I want convert this

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.