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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:38:39+00:00 2026-05-31T02:38:39+00:00

I have a xml which I want it to be extracted using OpenXML within

  • 0

I have a xml which I want it to be extracted using OpenXML within SQL Server

Here is the sample XML

<row>
  <student_token>7</student_token>
  <student_ssn>552</student_ssn>
  <alternate_id>20</alternate_id>
  <old_ssn xsi:nil="true" />
  <alien_num xsi:nil="true" />
  <last_name>A</last_name>
  <first_name>B</first_name>
  <middle_init xsi:nil="true" />
  <drivers_license_num xsi:nil="true" />
  <gpa_highschool xsi:nil="true" />
  <created_dt>2006-07-13T11:15:08.320</created_dt>
  <created_how>4</created_how>
  <modified_dt>2008-02-14T00:00:00</modified_dt>
  <modified_by>4</modified_by>
  <primary_street2 xsi:nil="true" />
  <primary_street3 xsi:nil="true" />
  <primary_country xsi:nil="true" />
  <email_address xsi:nil="true" />
  <address_start_dt xsi:nil="true" />
  <address_end_dt xsi:nil="true" />
  <entrance_iv_dt xsi:nil="true" />
  <entrance_iv_by xsi:nil="true" />
  <exit_iv_dt>2006-11-02T00:00:00</exit_iv_dt>
  <exit_iv_by>156</exit_iv_by>
  <foreign_address_indicator>N</foreign_address_indicator>
  <foreign_postal_code xsi:nil="true" />
  <pin>J27841</pin>
  <web_id>J08614   </web_id>
  <prior_name xsi:nil="true" />
  <orig_eps xsi:nil="true" />
  <web_role>STU1</web_role>
  <heal_limit_flag>N</heal_limit_flag>
  <email_address_2>test@test.com</email_address_2>
  <cellular_telephone>415</cellular_telephone>
  <alt_loan_debt xsi:nil="true" />
  <web_last_login xsi:nil="true" />
  <foreign_country_code xsi:nil="true" />
  <entrance_iv_dt_grad_plus xsi:nil="true" />
  <entrance_iv_by_grad_plus xsi:nil="true" />
  <failed_logins>0</failed_logins>
  <hispanic xsi:nil="true" />
  <race xsi:nil="true" />
  <primary_phone_number_intl xsi:nil="true" />
  <security_version>0</security_version>
  <failed_challenge_response>0</failed_challenge_response>
  <require_pin_reset xsi:nil="true" />
</row>

The query should extract into 3 fields for each row

  1. FieldName
  2. FieldValue
  3. IsNull

For example the first row should be

  • FieldName = student_token – The node name would be the field name
  • FieldValue = 7
  • IsNull = false – IsNull is based on the attribute xsi:nil="true"

How can I do this?

  • 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-31T02:38:40+00:00Added an answer on May 31, 2026 at 2:38 am

    Sample data with namespace added.

    declare @xml xml 
    set @xml = 
    '<row xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <student_token>7</student_token>
      <student_ssn>552</student_ssn>
      <alternate_id>20</alternate_id>
      <old_ssn xsi:nil="true" />
      <alien_num xsi:nil="true" />
      <last_name>A</last_name>
      <first_name>B</first_name>
      <middle_init xsi:nil="true" />
      <drivers_license_num xsi:nil="true" />
      <gpa_highschool xsi:nil="true" />
      <created_dt>2006-07-13T11:15:08.320</created_dt>
      <created_how>4</created_how>
      <modified_dt>2008-02-14T00:00:00</modified_dt>
      <modified_by>4</modified_by>
      <primary_street2 xsi:nil="true" />
      <primary_street3 xsi:nil="true" />
      <primary_country xsi:nil="true" />
      <email_address xsi:nil="true" />
      <address_start_dt xsi:nil="true" />
      <address_end_dt xsi:nil="true" />
      <entrance_iv_dt xsi:nil="true" />
      <entrance_iv_by xsi:nil="true" />
      <exit_iv_dt>2006-11-02T00:00:00</exit_iv_dt>
      <exit_iv_by>156</exit_iv_by>
      <foreign_address_indicator>N</foreign_address_indicator>
      <foreign_postal_code xsi:nil="true" />
      <pin>J27841</pin>
      <web_id>J08614   </web_id>
      <prior_name xsi:nil="true" />
      <orig_eps xsi:nil="true" />
      <web_role>STU1</web_role>
      <heal_limit_flag>N</heal_limit_flag>
      <email_address_2>test@test.com</email_address_2>
      <cellular_telephone>415</cellular_telephone>
      <alt_loan_debt xsi:nil="true" />
      <web_last_login xsi:nil="true" />
      <foreign_country_code xsi:nil="true" />
      <entrance_iv_dt_grad_plus xsi:nil="true" />
      <entrance_iv_by_grad_plus xsi:nil="true" />
      <failed_logins>0</failed_logins>
      <hispanic xsi:nil="true" />
      <race xsi:nil="true" />
      <primary_phone_number_intl xsi:nil="true" />
      <security_version>0</security_version>
      <failed_challenge_response>0</failed_challenge_response>
      <require_pin_reset xsi:nil="true" />
    </row>'
    

    Using openxml.

    declare @idoc int
    exec sp_xml_preparedocument @idoc out, @xml, '<row xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>'
    
    select FieldName, 
           FieldValue,
           isnull([IsNull], 0)
    from openxml(@idoc, '/row/*',1) 
      with (
             FieldName  varchar(50) '@mp:localname',
             FieldValue varchar(50) '.',
             [IsNull]   bit         '@xsi:nil'
           )
    
    exec sp_xml_removedocument @idoc
    

    Using the XML data type:

    ;with xmlnamespaces('http://www.w3.org/2001/XMLSchema-instance' as ns)
    select T.N.value('local-name(.)', 'varchar(50)') as FieldName,
           T.N.value('.', 'varchar(50)') as FieldValue,
           isnull(T.N.value('@ns:nil', 'bit'), 0) as [IsNull]
    from @xml.nodes('/row/*') as T(N)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a xml file which I want to edit using automatic data binding
I have XML in the following format which I want to reformat: <blocks> <!--
I want to commit a large amount of XML files which have been modified.
I have a xml which is max 3 levels deep. Now by using C#
I have an XML file which I need to parse using PHP and send
I have an application which extracts data from an XML file using XPath. If
I have an XML file in which I want to extract data from certain
I have extracted an XML file (using Export Test Suite functionality) in TestLink. The
I have a Java WebService setup which consumes an xml file and want to
HI there, I have an xml that is dynamically generated, from which I want

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.