#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    103
    Rep Power
    15

    Generate XML from MySql using PHP


    Hi,

    I have a very specific problem.

    I want to create an XML output from MySql using PHP (Without using DOMXML)

    The table structure is like this:

    id parent label
    -- ------ -----
    1 0 file
    2 1 load
    3 1 save
    4 1 print
    5 0 edit
    6 5 cut
    7 5 copy
    8 5 paste
    9 5 sub-menu
    10 9 nothing here

    and i want to output and XML like this:

    <menu>
    <menu-title label="file">
    <menu-item label="load" />
    <menu-item label="save" />
    <menu-item label="print" />
    </menu-title>
    <menu-title label="edit">
    <menu-item label="cut" />
    <menu-item label="copy" />
    <menu-item label="paste" />
    <menu-item label="sub-menu">
    <menu-item label="nothing here" />
    </menu-item>
    </menu-title>
    </menu>

    As you might have figured out, this is the XML i need to create some sort of a DROP DOWN menu with SUBMENU.

    Can someone tell me how to do this?

    Thanks.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2003
    Posts
    778
    Rep Power
    15
    As simple as printf()

    --
    http://www.raditha.com/megaupload/
    PHP file upload progress monitor.
    Last edited by e4c5; January 1st, 2004 at 08:26 AM.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    103
    Rep Power
    15
    its not as simple as that...... if you think so then i would really like to see an example otherwise people would not have duild DOMXML....

    i maybe wrong.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2003
    Posts
    778
    Rep Power
    15
    hi,

    I am unfortunately not in a position to give you an example. However i have been using this approach successfully since 2000. (I have also used dom on occaision)


    Why do you say you will not have valid xml? you control the data? if you escape the special character using one of several mechanism available you will not have any problems at all.

    --
    http://www.raditha.com/megaupload/
    PHP file upload progress monitor.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    103
    Rep Power
    15
    ok, i will try this out...
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2003
    Posts
    778
    Rep Power
    15
    All the best.

    To take it a litlle further: though dom looks pretty neat it does consume a lot more memory than using printf. So you will gain if you serve a lot of users. Secondly IMHO DOM is infact quite cumbersome to use.

    --
    http://www.raditha.com/megaupload/
    PHP file upload progress monitor.

IMN logo majestic logo threadwatch logo seochat tools logo