Ok, here is what I’m trying to do. I have a table that contains information about a menu.
From this table I need to create an xml file that has the same hierarchy as I’m going to have when the menu is created. For example, let’s assume that this is the final menu structure that I’m looking for. The items in the parentheses are the menu names.
Format (mnuFormat)
----Align (mnuFormatAlign)
--------Left (mnuFormatAlignLeft)
--------Center (mnuFormatAlignCenter)
--------Right (mnuFormatAlignRight)
----Make Same Size (mnuFormatSize)
--------Height (mnuFormatSizeHeight)
--------Width (mnuFormatSizeWidth)
--------Both (mnuFormatSizeBoth)
Debug (mnuDebug)
----Step into (mnuDebugInto)
----Step Over (mnuDebugOver)
Run (mnuRun)
----Start (mnuRunStart)
----Start With Full Compile (mnuRunFullCompile)
I would like the xml file that I generate to look like this.
I assume that I will have to create some recursive function that will go through the recordset and add nodes based on its parent.
The problem that I’m having is….
How do I find a node based on the name attribute (these are unique) and then insert a child node that contains attributes after that node?
With the code that you gave me Martin, I can insert a child node but can’t figure out how to add attributes to it. It is also placing it after the last element created. I can’t figure out how to tell it where to place it.
Originally posted by MartinLiss I'm having trouble understanding what you are starting with. Are you creating the xml file from the menu?
Ultimately I need to create the xml from a table.
Currently, what I have is an asp page that has a menu that is being populated using a static xml file and rendered using an xsl file.
Now I need to give the users options on what menu items they want to see. I’m moving away from a static xml file to a table driven approach. The user choice will be stored in a users table. Let’s say for example the user only wants to see a menu like this
Format (mnuFormat) 1
----Make Same Size (mnuFormatSize) 5
--------Height (mnuFormatSizeHeight) 9
--------Width (mnuFormatSizeWidth) 10
--------Both (mnuFormatSizeBoth) 11
Run (mnuRun) 3
----Start (mnuRunStart) 14
When the user logs on, the user’s options are retrieved from a users table and their menu choice are used to create a record set. This record set will contain all the menu entries that I have to generate xml for.
SELECT *
FROM tbl_menu
WHERE (MenuID IN (1,5,9,10,11,3,14))
From this record set I need to build the menu xml. It needs to have the hierarchy that you see above in order for it to work with the xsl that we currently have in place.
Why are you bothering with XML? You have the table, just store the user's selection as a string (eg "1,5,9,10,11,3,14") in the Registry and read it from there when you need it.