473,399 Members | 2,159 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Convert XML file

Hello,

Could someone tell me how to convert a XML file into another XML file
using a XSL file with a parameter? I created the code to do it, and it
seems ok, but it is not working.

Could somebody, please, help me out? I am on this for days.

My code is as follows:

Dim webSiteMap As XmlDocument = New XmlDocument
webSiteMap.Load(HttpContext.Current.Server.MapPath ("~/INPUT.XML"))
Dim googleXsl As XslCompiledTransform = New XslCompiledTransform

googleXsl.Load(HttpContext.Current.Server.MapPath( "~/CONVERT.XSL"))

Dim googleXslArguments As XsltArgumentList = New XsltArgumentList
googleXslArguments.AddParam("Domain", "",
"http://www.domain.com")

Dim webSiteMapStream As MemoryStream = New MemoryStream
googleXsl.Transform(webSiteMap, googleXslArguments,
webSiteMapStream)

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

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

Thanks,
Miguel

Nov 15 '06 #1
3 3139
Han
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.

"shapper" <md*****@gmail.comwrote in message
news:11*********************@i42g2000cwa.googlegro ups.com...
Hello,

Could someone tell me how to convert a XML file into another XML file
using a XSL file with a parameter? I created the code to do it, and it
seems ok, but it is not working.

Could somebody, please, help me out? I am on this for days.

My code is as follows:

Dim webSiteMap As XmlDocument = New XmlDocument
webSiteMap.Load(HttpContext.Current.Server.MapPath ("~/INPUT.XML"))
Dim googleXsl As XslCompiledTransform = New XslCompiledTransform

googleXsl.Load(HttpContext.Current.Server.MapPath( "~/CONVERT.XSL"))

Dim googleXslArguments As XsltArgumentList = New XsltArgumentList
googleXslArguments.AddParam("Domain", "",
"http://www.domain.com")

Dim webSiteMapStream As MemoryStream = New MemoryStream
googleXsl.Transform(webSiteMap, googleXslArguments,
webSiteMapStream)

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

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

Thanks,
Miguel

Nov 16 '06 #2
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/uti...btocsharp.aspx)

The error I am getting is:
XML Parsing Error: not well-formed
Location: http://localhost:1132/GaragemRamos%202006a/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:output method="xml" version="1.0" encoding="UTF-8"
indent="yes"/>
<xsl:param 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(goo gleSiteMapStream.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)(webSi teMap)),
googleXslArguments, googleSiteMapStream);
googleSiteMapStream.Flush();
googleSiteMapStream.Position = 0;
context.Response.Clear();
context.Response.ContentType = "text/xml; charset=utf-8";
context.Response.Write(Encoding.UTF8.GetString(goo gleSiteMapStream.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

Han wrote:
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.

"shapper" <md*****@gmail.comwrote in message
news:11*********************@i42g2000cwa.googlegro ups.com...
Hello,

Could someone tell me how to convert a XML file into another XML file
using a XSL file with a parameter? I created the code to do it, and it
seems ok, but it is not working.

Could somebody, please, help me out? I am on this for days.

My code is as follows:

Dim webSiteMap As XmlDocument = New XmlDocument
webSiteMap.Load(HttpContext.Current.Server.MapPath ("~/INPUT.XML"))
Dim googleXsl As XslCompiledTransform = New XslCompiledTransform

googleXsl.Load(HttpContext.Current.Server.MapPath( "~/CONVERT.XSL"))

Dim googleXslArguments As XsltArgumentList = New XsltArgumentList
googleXslArguments.AddParam("Domain", "",
"http://www.domain.com")

Dim webSiteMapStream As MemoryStream = New MemoryStream
googleXsl.Transform(webSiteMap, googleXslArguments,
webSiteMapStream)

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

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

Thanks,
Miguel
Nov 16 '06 #3
Please,

Could someone help me out?

I just posted my entire code. I still wasn't able to solve my problem

Thank You Very Much,

Miguel

shapper wrote:
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/uti...btocsharp.aspx)

The error I am getting is:
XML Parsing Error: not well-formed
Location: http://localhost:1132/GaragemRamos%202006a/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:output method="xml" version="1.0" encoding="UTF-8"
indent="yes"/>
<xsl:param 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(goo gleSiteMapStream.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)(webSi teMap)),
googleXslArguments, googleSiteMapStream);
googleSiteMapStream.Flush();
googleSiteMapStream.Position = 0;
context.Response.Clear();
context.Response.ContentType = "text/xml; charset=utf-8";
context.Response.Write(Encoding.UTF8.GetString(goo gleSiteMapStream.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

Han wrote:
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.

"shapper" <md*****@gmail.comwrote in message
news:11*********************@i42g2000cwa.googlegro ups.com...
Hello,
>
Could someone tell me how to convert a XML file into another XML file
using a XSL file with a parameter? I created the code to do it, and it
seems ok, but it is not working.
>
Could somebody, please, help me out? I am on this for days.
>
My code is as follows:
>
Dim webSiteMap As XmlDocument = New XmlDocument
>
>
webSiteMap.Load(HttpContext.Current.Server.MapPath ("~/INPUT.XML"))
Dim googleXsl As XslCompiledTransform = New XslCompiledTransform
>
googleXsl.Load(HttpContext.Current.Server.MapPath( "~/CONVERT.XSL"))
>
Dim googleXslArguments As XsltArgumentList = New XsltArgumentList
googleXslArguments.AddParam("Domain", "",
"http://www.domain.com")
>
Dim webSiteMapStream As MemoryStream = New MemoryStream
googleXsl.Transform(webSiteMap, googleXslArguments,
webSiteMapStream)
>
context.Response.Clear()
context.Response.ContentType = "text/xml; charset=utf-8"
>
context.Response.Write(Encoding.UTF8.GetString(web SiteMapStream.GetBuffer))
context.Response.End()
>
Thanks,
Miguel
>
Nov 17 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: hunterb | last post by:
I have a file which has no BOM and contains mostly single byte chars. There are numerous double byte chars (Japanese) which appear throughout. I need to take the resulting Unicode and store it in a...
7
by: whatluo | last post by:
Hi, all I'm now working on a program which will convert dec number to hex and oct and bin respectively, I've checked the clc but with no luck, so can anybody give me a hit how to make this done...
1
by: Daniel | last post by:
I have looked everywhere on the web for an answer to this and the only thing I can find is converting the image format when the file is present on the local filesystem. What I want to do is use a...
7
by: Scott Schluer | last post by:
Is there a way to use the Image class to convert a color photo (GIF or JPEG) to a B&W photo? Thanks, Scott
3
by: Thubaiti | last post by:
Hi, I have this code in my ASP.NET and I want to convert it to C# (code behind) <asp:Repeater id="subCategoryRepeater" runat="server"> <ItemTemplate> <ul> <li> <asp:HyperLink...
12
by: Brian Henry | last post by:
first question... I have a flat file which unfortinuatly has columns seperated by nulls instead of spaces (a higher up company created it this way for us) is there anyway to do a readline with this...
5
by: melickas | last post by:
We designed a custom application using Office Developer Tools '97 which included a Run-time version of Access--- so it would not matter if our customer even had any version of Access on their...
6
by: PenguinPig | last post by:
Dear All Experts I would like to know how to convert a HTML into Image using C#. Or allow me contains HTML code (parsed) in Image? I also tried this way but it just display the character "<" &...
5
by: sonu | last post by:
hey good morning ...... how to convert a video file in .flv format in php for linux hosting......is there any package whis provide this facility . Can i use ffmpeg for linux hosting...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.