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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:25:29+00:00 2026-05-11T18:25:29+00:00

I have a task of parsing a simple XML-formatted string in a MySQL stored

  • 0

I have a task of parsing a simple XML-formatted string in a MySQL stored procedure. XML looks like this (testing purposes only):

<parent>
    <child>Example 1</child>
    <child>Example 2</child>
</parent>

What I need MySQL to do is to produce a result set one row per match. My stored proc code looks like this:

DECLARE xmlDoc TEXT;
SET xmlDoc = '<parent><child>Example 1</child><child>Example 2</child></parent>';
SELECT ExtractValue(xmlDoc, '//child');

What this does, however, is it concatenate all the matches, producing “Example 1 Example 2”. This is, by the way, documented, but quite useless behavior.

What can I do to make it return the matches in rows without having to count the matches and processing them one-by-one? Is it even possible with MySQL?

Thanks all!

  • 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-11T18:25:30+00:00Added an answer on May 11, 2026 at 6:25 pm
    DECLARE i INT DEFAULT 1;
    DECLARE count DEFAULT ExtractValue(xml, 'count(//child)');
    
    WHILE i <= count DO
        SELECT ExtractValue(xml, '//child[$i]');
        SET i = i+1;
    END WHILE
    

    Alternatively…

    DECLARE v VARCHAR(500) DEFAULT '';
    DECLARE i INT DEFAULT 1;
    
    REPEAT
        SET v = ExtractValue(xml, '//child[$i]')
        SET i = i+1;
        IF v IS NOT NULL THEN
            -- do something with v
        END IF
    UNTIL v IS NULL
    

    Sorry if the syntax is a bit shakey in here, not much of a mysql guru…

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

Sidebar

Related Questions

This is a very simple task in every language I have ever used, but
I have this Task model: class Task < ActiveRecord::Base acts_as_tree :order => 'sort_order' end
I'm relatively new to Nant, what i'd like to do is have a task
For customer service week this year, I have the privileged task of creating a
I have some slow internet task to save and load file, I'd like to
I have sample code written for parsing xml file using javax.xml package. it uses
I have been set a task of natural language parsing in Prolog. So far
If I have a string like a/{b,c,d}/e then I want to be able to
I have a task to convert the data design in XML format to a
After reading this question I have this rake task: desc Import sales task :import_sales

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.