Re: Output SiteMapNodeCollection as an XML file?
- From: "Ken Cox [Microsoft MVP]" <BANSPAMkjopc@xxxxxxxxxxxxxxxxx>
- Date: Thu, 13 Jul 2006 09:37:58 -0400
Try this?
Ken
Microsoft MVP [ASP.NET]
<%@ webhandler class="FlashSiteMap" language="VB" %>
' FlashSiteMap.ashx
' Gets the root and sitemap nodes and renders them
' via a handler to XML
' Uses recursion to write the
' childnodes for a given node
' Ken Cox [MVP] ASP.NET
' Adapted from Stephen Walther's code
' in ASP.NET 2.0 Unleashed, Chapter 18
Imports System
Imports System.Web
Imports System.Xml
Imports System.Text
Imports System.IO
Public Class FlashSiteMap
Implements IHttpHandler
Private writer_xml As XmlWriter
Public Sub ProcessRequest _
(ByVal context As HttpContext) _
Implements IHttpHandler.ProcessRequest
context.Response.ContentType = "text/xml"
Dim settings As New XmlWriterSettings()
settings.Encoding = Encoding.UTF8
settings.Indent = True
settings.NewLineHandling = NewLineHandling.Entitize
settings.NewLineOnAttributes = True
writer_xml = XmlWriter.Create _
(context.Response.OutputStream, settings)
writer_xml.WriteStartDocument()
writer_xml.WriteStartElement _
("siteMap", "http://schemas.microsoft.com/AspNet/SiteMap-File-1.0")
' Write the root node
writer_xml.WriteStartElement("siteMapNode")
writer_xml.WriteStartAttribute("url")
writer_xml.WriteString(SiteMap.RootNode.Url)
writer_xml.WriteEndAttribute()
writer_xml.WriteStartAttribute("title")
writer_xml.WriteString(SiteMap.RootNode.Title)
writer_xml.WriteEndAttribute()
writer_xml.WriteStartAttribute("description")
writer_xml.WriteString(SiteMap.RootNode.Description)
writer_xml.WriteEndAttribute()
' Write the child nodes
'*******Recursive call here *******
RecurseSiteMapNode(SiteMap.RootNode.ChildNodes)
' Finish the root node
writer_xml.WriteEndElement()
' Finish the start of the childnodes
writer_xml.WriteEndElement()
' Finish the document
writer_xml.WriteEndDocument()
writer_xml.Flush()
End Sub
Sub RecurseSiteMapNode(ByVal nodes As SiteMapNodeCollection)
For Each newnode As SiteMapNode In nodes
writer_xml.WriteStartElement("siteMapNode")
writer_xml.WriteStartAttribute("url")
writer_xml.WriteString(newnode.Url)
writer_xml.WriteEndAttribute()
writer_xml.WriteStartAttribute("title")
writer_xml.WriteString(newnode.Title)
writer_xml.WriteEndAttribute()
writer_xml.WriteStartAttribute("description")
writer_xml.WriteString(newnode.Description)
writer_xml.WriteEndAttribute()
RecurseSiteMapNode(newnode.ChildNodes)
writer_xml.WriteEndElement()
Next
End Sub
Public ReadOnly Property IsReusable() _
As Boolean Implements IHttpHandler.IsReusable
Get
Return True
End Get
End Property
End Class
"JJ" <abc@xxxxxxx> wrote in message
news:u%238fyIkpGHA.2292@xxxxxxxxxxxxxxxxxxxxxxx
It chops off the root node. I need that one as its displayed in the actual
web.sitemap.
.
- Follow-Ups:
- References:
- Output SiteMapNodeCollection as an XML file?
- From: JJ
- Re: Output SiteMapNodeCollection as an XML file?
- From: Ken Cox [Microsoft MVP]
- Re: Output SiteMapNodeCollection as an XML file?
- From: JJ
- Re: Output SiteMapNodeCollection as an XML file?
- From: Ken Cox [Microsoft MVP]
- Re: Output SiteMapNodeCollection as an XML file?
- From: JJ
- Re: Output SiteMapNodeCollection as an XML file?
- From: Ken Cox [Microsoft MVP]
- Re: Output SiteMapNodeCollection as an XML file?
- From: JJ
- Output SiteMapNodeCollection as an XML file?
- Prev by Date: Re: Window.Open / Window.Close question
- Next by Date: Custom controls vs Web parts
- Previous by thread: Re: Output SiteMapNodeCollection as an XML file?
- Next by thread: Re: Output SiteMapNodeCollection as an XML file?
- Index(es):
Relevant Pages
|
Loading