By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,885 Members | 1,072 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,885 IT Pros & Developers. It's quick & easy.

Can't display file in Browser. Need help please! Thank you.

P: n/a
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.ProcessRequest

' Create ASP.NET web site map
Dim webSiteMap As XmlDocument = New XmlDocument

' Load ASP.NET's site map

webSiteMap.Load(HttpContext.Current.Server.MapPath (ConfigurationManager.AppSettings("~/Web.sitemap"))

' Create google xsl document
Dim googleXsl As XslCompiledTransform = New XslCompiledTransform

' Load google xml document

googleXsl.Load(HttpContext.Current.Server.MapPath( "~/SiteMap.xsl"))

' Create xsl arguments list
Dim googleXslArguments As XsltArgumentList = New XsltArgumentList
googleXslArguments.AddParam("Domain", "",
"http://www.domain.com")

' Create the ASP.NET's site map memory stream
Dim webSiteMapStream As MemoryStream = New MemoryStream

' Transform Asp.Net's site map to Google's site map and add it to
stream
googleXsl.Transform(webSiteMap, googleXslArguments,
webSiteMapStream)

' Output Google sitemap
context.Response.Clear()
context.Response.ContentType = "text/xml; charset=utf-8"

context.Response.Write(Encoding.UTF8.GetString(web SiteMapStream.GetBuffer))
context.Response.End()

End Sub

' Define is handler is reusable
Public ReadOnly Property IsReusable() As Boolean Implements
IHttpHandler.IsReusable
Get
Return False
End Get
End Property

End Class

--------- XSL --------

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
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.microsoft.com/AspNet/SiteMap-File-1.0">
<xsl:output method="xml" version="1.0" encoding="UTF-8"
indent="yes"/>
<xsl:param name="By27.WebSite.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:siteMapNode">
<xsl:element name="url">
<xsl:element name="loc">
<xsl:value-of select="$Domain" />
<xsl:value-of select="substring(@url, 3)"/>
</xsl:element>
<xsl:element name="lastmod">
<xsl:value-of select="@lastmod"/>
</xsl:element>
<xsl:element name="changefreq">
<xsl:value-of select="@changefreq"/>
</xsl:element>
<xsl:element name="priority">
<xsl:value-of select="@priority"/>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>

Nov 13 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Please, could someone help me out?
I have been trying to solve this for days.
I am never able to see the XML file in the browser.

Thanks,
Miguel

shapper wrote:
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.ProcessRequest

' Create ASP.NET web site map
Dim webSiteMap As XmlDocument = New XmlDocument

' Load ASP.NET's site map

webSiteMap.Load(HttpContext.Current.Server.MapPath (ConfigurationManager.AppSettings("~/Web.sitemap"))

' Create google xsl document
Dim googleXsl As XslCompiledTransform = New XslCompiledTransform

' Load google xml document

googleXsl.Load(HttpContext.Current.Server.MapPath( "~/SiteMap.xsl"))

' Create xsl arguments list
Dim googleXslArguments As XsltArgumentList = New XsltArgumentList
googleXslArguments.AddParam("Domain", "",
"http://www.domain.com")

' Create the ASP.NET's site map memory stream
Dim webSiteMapStream As MemoryStream = New MemoryStream

' Transform Asp.Net's site map to Google's site map and add it to
stream
googleXsl.Transform(webSiteMap, googleXslArguments,
webSiteMapStream)

' Output Google sitemap
context.Response.Clear()
context.Response.ContentType = "text/xml; charset=utf-8"

context.Response.Write(Encoding.UTF8.GetString(web SiteMapStream.GetBuffer))
context.Response.End()

End Sub

' Define is handler is reusable
Public ReadOnly Property IsReusable() As Boolean Implements
IHttpHandler.IsReusable
Get
Return False
End Get
End Property

End Class

--------- XSL --------

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
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.microsoft.com/AspNet/SiteMap-File-1.0">
<xsl:output method="xml" version="1.0" encoding="UTF-8"
indent="yes"/>
<xsl:param name="By27.WebSite.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:siteMapNode">
<xsl:element name="url">
<xsl:element name="loc">
<xsl:value-of select="$Domain" />
<xsl:value-of select="substring(@url, 3)"/>
</xsl:element>
<xsl:element name="lastmod">
<xsl:value-of select="@lastmod"/>
</xsl:element>
<xsl:element name="changefreq">
<xsl:value-of select="@changefreq"/>
</xsl:element>
<xsl:element name="priority">
<xsl:value-of select="@priority"/>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Nov 14 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.