Hello,
I am trying to convert an Asp.Net XML sitemap file in a Google XMl
sitemap file using a XSL file using an HttpHandler.
Everything seems well in my code but I am getting an error:
XML Parsing Error: not well-formed
Location: http://localhost:1132/WebSite/Google
Line Number 2, Column 62:<urlset
xmlns="http://www.google.com/schemas/sitemap/0.84" />
I tried to display it as Text instead of Text/XML. I don't get the same
error. I just get a bunch of squares after the line:
Line Number 2, Column 62:<urlset
xmlns="http://www.google.com/schemas/sitemap/0.84" />
Could somebody help me out? I tried everything I could think of for the
past 2 days.
I post my entire code in this post.
Thanks,
Miguel
--------- HttpHandler --------
Public Class SiteMap : Implements IHttpHandler
' -- [Methods] -------------------------------------------
' Define handler process request
Public Sub ProcessRequest( ByVal context As HttpContext) Implements
IHttpHandler.Pr ocessRequest
' Create ASP.NET web site map
Dim webSiteMap As XmlDocument = New XmlDocument
' Load ASP.NET's site map
webSiteMap.Load (HttpContext.Cu rrent.Server.Ma pPath(Configura tionManager.App Settings("~/Web.sitemap"))
' Create google xsl document
Dim googleXsl As XslCompiledTran sform = New XslCompiledTran sform
' Load google xml document
googleXsl.Load( HttpContext.Cur rent.Server.Map Path("~/SiteMap.xsl"))
' Create xsl arguments list
Dim googleXslArgume nts As XsltArgumentLis t = New XsltArgumentLis t
googleXslArgume nts.AddParam("D omain", "",
"http://www.domain.com" )
' Create the ASP.NET's site map memory stream
Dim webSiteMapStrea m As MemoryStream = New MemoryStream
' Transform Asp.Net's site map to Google's site map and add it to
stream
googleXsl.Trans form(webSiteMap , googleXslArgume nts,
webSiteMapStrea m)
' Output Google sitemap
context.Respons e.Clear()
context.Respons e.ContentType = "text/xml; charset=utf-8"
context.Respons e.Write(Encodin g.UTF8.GetStrin g(webSiteMapStr eam.GetBuffer))
context.Respons e.End()
End Sub
' Define is handler is reusable
Public ReadOnly Property IsReusable() As Boolean Implements
IHttpHandler.Is Reusable
Get
Return False
End Get
End Property
End Class
--------- XSL --------
<?xml version="1.0" encoding="utf-8"?>
<xsl:styleshe et
version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns="http://www.google.com/schemas/sitemap/0.84"
xmlns:dk="http://schemas.microso ft.com/AspNet/SiteMap-File-1.0">
<xsl:output method="xml" version="1.0" encoding="UTF-8"
indent="yes"/>
<xsl:param name="By27.WebS ite.Url"/>
<xsl:template match="dk:*"/>
<xsl:template match="@*|text( )|comment()"/>
<xsl:template match="/">
<xsl:element name="urlset">
<xsl:apply-templates select="//dk:siteMapNode[@google='true']"/>
</xsl:element>
</xsl:template>
<xsl:template match="dk:siteM apNode">
<xsl:element name="url">
<xsl:element name="loc">
<xsl:value-of select="$Domain " />
<xsl:value-of select="substri ng(@url, 3)"/>
</xsl:element>
<xsl:element name="lastmod">
<xsl:value-of select="@lastmo d"/>
</xsl:element>
<xsl:element name="changefre q">
<xsl:value-of select="@change freq"/>
</xsl:element>
<xsl:element name="priority" >
<xsl:value-of select="@priori ty"/>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>