November 1, 2010 at 3:21 am
Hi all,
I need help,
I have un xml file like this:
<?xml version="1.0" encoding="utf-8" ?>
<rootMenu>
<topMenu text="Button1">
<menuItem href="template.aspx" text="B1I1" />
<menuItem href="template.aspx" text="B1I2" />
<menuItem text="B1I3">
<menuItem href="template.aspx" text="B1I3I1" />
<menuItem href="template.aspx" text="B1I3I2" />
</menuItem>
</topMenu>
<topMenu text="Button2">
<menuItem href="template.aspx" text="B2I1" />
<menuItem href="template.aspx" text="B2I2" />
<menuItem href="template.aspx" text="B2I3" />
<menuItem text="B2I4">
<menuItem text="B2I4I1">
<menuItem href="template.aspx" text="B2I4I1I1I1" />
</menuItem>
</menuItem>
</topMenu>
</rootMenu>
It's a multi-level menu, i want to get it from my database. i don't know How?
If i need one table or many?
Please help
Thanks
November 18, 2010 at 1:06 pm
Try this.
create table Menu (ParentID int, ID int, menuText varchar(100) , href varchar(100))
insert into Menu values (null, 1, 'Button1', null)
insert into Menu values (null, 2, 'Button2', null)
insert into Menu values (1, 3, 'Sub1', 'index.html')
insert into Menu values (1, 4, 'Sub2', 'index.html')
insert into Menu values (2, 5, 'Suba', 'index.html')
insert into Menu values (2, 6, 'Subb', 'index.html')
select menuText [@text],
(select href as [@href], menuText as [@text]
from Menu ms where ms.ParentID = mt.ID
for xml path ('menuItem'), Type
)
from Menu mt
where ParentID is null
for xml path ('topMenu'), root ('rootMenu')
Russel Loski, MCSE Business Intelligence, Data Platform
November 19, 2010 at 1:36 am
Are you using the same Type mentioned here: http://www.sqlservercentral.com/Forums/Topic1016736-21-1.aspx
?
November 19, 2010 at 6:03 am
Is it the same "Type" that is mentioned in the other post? Yes.
Russel Loski, MCSE Business Intelligence, Data Platform
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply