Hi,
I am posting my XSL and XML files as well the new version of my VB.NET
(I also post the conversion to C# using the VB.NET to C# converter
available in
http://www.developerfusion.co.uk/utilities/convertvbtocsharp.aspx)
The error I am getting is:
XML Parsing Error: not well-formed
Location:
http://localhost:1132/GaragemRamos 2006a/Google
Line Number 2, Column 62:<urlset
xmlns="
http://www.google.com/schemas/sitemap/0.84" />
Thanks,
Miguel
--------- XSL CODE ---------
<?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
utput method="xml" version="1.0" encoding="UTF-8"
indent="yes"/>
<xsl
aram name="WebSiteUrl"/>
<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="$WebSiteUrl" />
<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>
--------- VB.NET Code ---------
' Create ASP.NET web site map
Dim webSiteMap As XmlDocument = New XmlDocument
' Load ASP.NET's site map
webSiteMap.Load(HttpContext.Current.Server.MapPath("~/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("WebSiteUrl", "",
"
http://www.mydomain.com")
' Create the ASP.NET's site map memory stream
Dim googleSiteMapStream As MemoryStream = New MemoryStream
' Transform Asp.Net's site map to Google's site map and add it to
stream
googleXsl.Transform(CType(webSiteMap, XPath.IXPathNavigable),
googleXslArguments, googleSiteMapStream)
' Flush google site map stream
googleSiteMapStream.Flush()
' Set google site map stream position to 0
googleSiteMapStream.Position = 0
' Output Google sitemap
context.Response.Clear()
context.Response.ContentType = "text/xml; charset=utf-8"
context.Response.Write(Encoding.UTF8.GetString(googleSiteMapStream.GetBuffer))
context.Response.End()
--------- C# CODE ---------
XmlDocument webSiteMap = new XmlDocument();
webSiteMap.Load(HttpContext.Current.Server.MapPath("~/Web.sitemap"));
XslCompiledTransform googleXsl = new XslCompiledTransform();
XsltArgumentList googleXslArguments = new XsltArgumentList();
googleXslArguments.AddParam("WebSiteUrl", "",
"
http://www.mydomain.com");
MemoryStream googleSiteMapStream = new MemoryStream();
googleXsl.Transform(((XPath.IXPathNavigable)(webSiteMap)),
googleXslArguments, googleSiteMapStream);
googleSiteMapStream.Flush();
googleSiteMapStream.Position = 0;
context.Response.Clear();
context.Response.ContentType = "text/xml; charset=utf-8";
context.Response.Write(Encoding.UTF8.GetString(googleSiteMapStream.GetBuffer));
context.Response.End();
--------- XML File (Web.sitemap) ---------
<?xml version="1.0" encoding="utf-8" ?>
<siteMap
xmlns="
http://schemas.microsoft.com/ASPNet/SiteMap-File-1.0" >
<siteMapNode>
<siteMapNode
url="~/Default.aspx"
title="Home"
description="Desc1"
changefreq="daily"
lastmod="2006-11-01T20:25:42+01:00"
priority="1"
google="true" />
<siteMapNode
url="~/Company.aspx"
title="Company"
description="Desc2"
changefreq="daily"
lastmod="2006-11-01T20:25:42+01:00"
priority="0.2"
google="true" />
<siteMapNode
url="~/Contacts.aspx"
title="Contacts"
description="Contacts"
changefreq="daily"
lastmod="2006-11-01T20:25:42+01:00"
priority="0.4"
google="false" />
</siteMapNode>
</siteMap>
Well, that is all I think. I hope someone can help me out.
Thank You Very Much,
Miguel
Hello shapper
What do you get from the code, error or empty page?
Temporarily I found a problem in your code. I don't know VB, anyway,
xsl.transform((ixpathNavigable)xmldocument, args, stream);
You should convert the xmldocument into xpathnavigator EXPLICITLY. I think
VB version is ctype.