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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:05:57+00:00 2026-06-13T07:05:57+00:00

I have never used XML before. I am trying to send a single XML

  • 0

I have never used XML before. I am trying to send a single XML file to SQL Server, where it will (hopefully) be able to be deconstructed and inserted into various tables.

I’m building tests. So for each test there are X questions, and for each question there are X answer options and 1 explanation of the correct answer. Is the following XML example valid? Am I missing anything that will simplify it?

<test>
    <testid>1</testid>
    <qablock>
        <question>
            <question_number>1</question_number>
            <question_text>What is 1 + 1?</question_text>
        </question>
        <explanation>It's 2.</explanation>
        <options>
            <option>
                <option_number>1</option_number>
                <option_value>1</option_value>
                <is_correct>0</is_correct>
            </option>
            <option>
                <option_number>2</option_number>
                <option_value>2</option_value>
                <is_correct>1</is_correct>
            </option>
            <option>
                <option_number>3</option_number>
                <option_value>3</option_value>
                <is_correct>0</is_correct>
            </option>
            <option>
                <option_number>4</option_number>
                <option_value>4</option_value>
                <is_correct>0</is_correct>
            </option>
            <option>
                <option_number>5</option_number>
                <option_value>5</option_value>
                <is_correct>0</is_correct>
            </option>
        </options>
    </qablock>
    <qablock>
        <question>
            <question_number>2</question_number>
            <question_text>What is 2 + 2?</question_text>
        </question>
        <explanation>It's 4.</explanation>
        <options>
            <option>
                <option_number>1</option_number>
                <option_value>1</option_value>
                <is_correct>0</is_correct>
            </option>
            <option>
                <option_number>2</option_number>
                <option_value>2</option_value>
                <is_correct>0</is_correct>
            </option>
            <option>
                <option_number>3</option_number>
                <option_value>3</option_value>
                <is_correct>0</is_correct>
            </option>
            <option>
                <option_number>4</option_number>
                <option_value>4</option_value>
                <is_correct>1</is_correct>
            </option>
            <option>
                <option_number>5</option_number>
                <option_value>5</option_value>
                <is_correct>0</is_correct>
            </option>
        </options>
    </qablock>
</test>
  • 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-13T07:05:58+00:00Added an answer on June 13, 2026 at 7:05 am

    What you’ve got there is perfectly valid XML. It doesn’t have a schema associated (i.e. so you can validate the structure / ensure that an XML file you’re given is as expected before using it so you don’t get unexpected results.

    You can add an XML header – that would help as it would tell the parser what character set to use – also check that you save the XML file with the encoding you specify in the header (let me know if you need more explanation on this point).

    Finally though what you’ve got is fine, personally I’d write that XML slightly differently to make it smaller and easier to read. There are no hard rules there, but generally speaking keeping file size down is good and being readable is good.

    Finally I’d probably wrap this in a tests element; that way if you want to upload more than one test at a time it’s easy to do (but you can still use this for one file at a time should you wish) – again no hard rule, but building in flexibility is always good.

    <?xml version="1.0" encoding="utf-8"?>
    <tests>
        <test testid='1'>
            <qablock number='1'>
                <question>What is 1 + 1?</question>
                <explanation>It's 2.</explanation>
                <options>
                    <option number='1' value='1' />
                    <option number='2' value='2' correct='true' />
                    <option number='3' value='3' />
                    <option number='4' value='4' />
                    <option number='5' value='5' />
                </options>
            </qablock>
            <qablock number='2'>
                <question>What is 2 + 2?</question>
                <explanation>It's 4.</explanation>
                <options>
                    <option number='1' value='1' />
                    <option number='2' value='2'/>
                    <option number='3' value='3' />
                    <option number='4' value='4' correct='true'  />
                    <option number='5' value='5' />
                </options>
            </qablock>
        </test>
    </tests>
    

    Hope that helps.

    ———–edit—————-

    Here’s an example of this with SQL’s xml data type;

    declare @x xml
    
    set @x = '<tests>
        <test testid=''1''>
            <qablock number=''1''>
                <question>What is 1 + 1?</question>
                <explanation>It''s 2.</explanation>
                <options>
                    <option number=''1'' value=''1'' />
                    <option number=''2'' value=''2'' correct=''true'' />
                    <option number=''3'' value=''3'' />
                    <option number=''4'' value=''4'' />
                    <option number=''5'' value=''5'' />
                </options>
            </qablock>
            <qablock number=''2''>
                <question>What is 2 + 2?</question>
                <explanation>It''s 4.</explanation>
                <options>
                    <option number=''1'' value=''1'' />
                    <option number=''2'' value=''2''/>
                    <option number=''3'' value=''3'' />
                    <option number=''4'' value=''4'' correct=''true''  />
                    <option number=''5'' value=''5'' />
                </options>
            </qablock>
        </test>
    </tests>'
    
    select @x.value('(/tests/test/qablock[@number=''2'']/question/text())[1]','nvarchar(max)') Question
    , @x.value('(/tests/test/qablock[@number=''2'']/options/option[@correct=''true'']/@number)[1]','nvarchar(max)') Answer
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just trying to understand that - I have never used it before. How is
I have never used Foxpro before. Can you convert the following Foxpro code into
I have never used array_combine before and I am getting a Boolean instead of
I have never used Try-catch in my code before, but now I need to
G'day, I have never really used excel formulas before but need to convert a
I've never programmed in java or eclipse before, although I have used c# and
This is really baffling me. I've never used XML before, so I'm just playing
Okay, so I have never used XSLT before, and I saw a couple of
I have never really used XSLT before and am looking for some advice. I
I have never used Perl, but I am really impressed by the ack ,

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.