Re: Output SiteMapNodeCollection as an XML file?



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.




.



Relevant Pages

  • Re: Root Domain Name
    ... Microsoft MVP - Windows NT Server ... > Alain. ... >> I would suggest your root AD domain be a child domain of your Internet ... >>> Active Directory deployment is plan with a single forest with a root ...
    (microsoft.public.windows.server.active_directory)
  • Re: Cannot Save Document in Word
    ... The answer lies in "how" you transferred those files over. ... It sounds as though they have come in "Owned" by the System (root) and not ... "The disk may be full or write-protected... ... John McGhie, Microsoft MVP, Word and Word:Mac ...
    (microsoft.public.mac.office.word)
  • Re: Redirecting Users...
    ... root portal page to redirect the user (you would hav eto have logic to ... the root site from another page). ... Microsoft MVP - SharePoint Portal Server ... > Also, I have this simple form for login the OWA WebParts, is it possible ...
    (microsoft.public.sharepoint.portalserver)
  • Re: How do I define multiple treeview node styles at the same level
    ... I don't even know what he means by a SiteMap. ... The top root node should not have a top border, ... >: child 1.1 ...
    (microsoft.public.vb.general.discussion)
  • Re: XML Menu Control
    ... I don't know if the Subject really hints at my question, ... to create an XML (sitemap) ile like so. ... Where when i user is located at the top root of the site they see ... This allows me to map one huge xml file but not have listed ...
    (microsoft.public.dotnet.framework.aspnet)

Loading