MySQL Forums
Forum List  »  Newbie

How to transform NESTED SETS to XML?
Posted by: helmut kn
Date: October 13, 2010 11:17PM

Hallo,

I'd need a MySQL query to transform my nested sets structure into XML. (no PHP).The Problem is how to close all tags correct.

EXAMPLE:
A[01,16]
B[02,03]    C[04,13]    H[14,15]
            D[05,12]
            E[06,07]    F[08,11]
                        G[09,10]

<A>content A<B>content B</B><C>content C<D>content D<E>content E</E><F>content F<G>content G</G></F></D></C><H>content H</H></A>



TESTING CONTENT:
CREATE TABLE IF NOT EXISTS `tree` (
  `id` int(11) NOT NULL,
  `tag` varchar(100) NOT NULL,
  `lft` int(11) NOT NULL,
  `rgt` int(11) NOT NULL,
  `desc` text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;


INSERT INTO `tree` (`id`, `tag`, `lft`, `rgt`, `desc`) VALUES
(1, 'A', 1, 16, 'content A'),
(2, 'B', 2, 3, 'content B'),
(3, 'C', 4, 13, 'content C'),
(4, 'D', 5, 12, 'content D'),
(5, 'E', 6, 7, 'content E'),
(6, 'F', 8, 11, 'content F'),
(7, 'G', 9, 10, 'content G'),
(8, 'H', 14, 15, 'content H');


thanks a lot for helping



Edited 1 time(s). Last edit at 10/14/2010 02:57AM by helmut kn.

Options: ReplyQuote


Subject
Written By
Posted
How to transform NESTED SETS to XML?
October 13, 2010 11:17PM
October 17, 2010 02:39AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.