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

S

shapper

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(webSiteMapStream.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:eek:utput 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>
 
S

shapper

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
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(webSiteMapStream.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:eek:utput 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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
474,057
Messages
2,570,443
Members
47,113
Latest member
XZJMike318

Latest Threads

Top