473,668 Members | 2,519 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MSXML leaves out encoding when using .NET

We're using MSXML to transform the XML document we have to an XHTML
file using an XSLT. Now the problem is that the dotnet implementation
we made does something subtly different from the commandline call to
MSXML. The problem is that the dotnet variant leaves out a piece of
info on the charset, leading to the browser going to a default encoding
instead of the wanted UTF-8.

MSXML2.DOMDocum ent40Class stylesheet = new
MSXML2.DOMDocum ent40Class();
stylesheet.asyn c = false;
source.validate OnParse = false;
stylesheet.load (xsls[i]);
string s = source.transfor mNode(styleshee t);
System.IO.TextW riter file = System.IO.File. CreateText("pat h.html");
file.Write(s);
Note that the xslt has a line:
<xsl:output method="html" indent="yes" encoding="UTF-8" />

This code creates a meta tag different from the commandline version:
<META http-equiv="Content-Type" content="text/html">

Whereas the commandline version of MSXML nicely outputs.
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">

Anyone have a clue how to do this? Do I need a
CreateProcessin gInstruction for the stylesheet?

Nov 9 '06 #1
5 5363

I think you have another option in DotNet... rather than MSXML2 library.

Here is some code I found as a starter:
public class XMLtoXSLTransfo rmWrapper
{

string debugMsg=null;

public void DoTranslation(s tring xmlFile, string xslFile, string
outputFile)
{

try
{

//Create a new XslTransform object.
XslTransform xslt = new XslTransform();

//Load the stylesheet.
xslt.Load(xslFi le);

//Create a new XPathDocument and load the XML data to be transformed.
XPathDocument mydata = new XPathDocument(x mlFile);

//Create an XmlTextWriter which outputs to the console.
//XmlWriter writer = new XmlTextWriter(C onsole.Out);

//Transform the data and send the output to the console.
//xslt.Transform( mydata,null,wri ter, null);
xslt.Transform (xmlFile, outputFile);
}
catch (Exception ex)
{
debugMsg = ex.Message;
Console.WriteLi ne (debugMsg);

}
}

public XMLtoXSLTransfo rmWrapper()
{
//
// TODO: Add constructor logic here
//
}
}
"Jeroen" <me******@gmail .comwrote in message
news:11******** **************@ i42g2000cwa.goo glegroups.com.. .
We're using MSXML to transform the XML document we have to an XHTML
file using an XSLT. Now the problem is that the dotnet implementation
we made does something subtly different from the commandline call to
MSXML. The problem is that the dotnet variant leaves out a piece of
info on the charset, leading to the browser going to a default encoding
instead of the wanted UTF-8.

MSXML2.DOMDocum ent40Class stylesheet = new
MSXML2.DOMDocum ent40Class();
stylesheet.asyn c = false;
source.validate OnParse = false;
stylesheet.load (xsls[i]);
string s = source.transfor mNode(styleshee t);
System.IO.TextW riter file = System.IO.File. CreateText("pat h.html");
file.Write(s);
Note that the xslt has a line:
<xsl:output method="html" indent="yes" encoding="UTF-8" />

This code creates a meta tag different from the commandline version:
<META http-equiv="Content-Type" content="text/html">

Whereas the commandline version of MSXML nicely outputs.
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">

Anyone have a clue how to do this? Do I need a
CreateProcessin gInstruction for the stylesheet?

Nov 9 '06 #2
Jeroen wrote:
We're using MSXML to transform the XML document we have to an XHTML
file using an XSLT.
Why do you use MSXML with a managed .NET application? With .NET 1.x you
should use System.Xml.Xsl. Xsl.Transform, with .NET 2.0 you should use
System.Xml.Xsl. Xsl.CompiledTra nsform for XSLT transformations .
string s = source.transfor mNode(styleshee t);
You get a string result with transformNode,
Note that the xslt has a line:
<xsl:output method="html" indent="yes" encoding="UTF-8" />

This code creates a meta tag different from the commandline version:
<META http-equiv="Content-Type" content="text/html">
and a string is simply a sequence of Unicode characters that does not
have an encoding. Encoding matters on the byte level, with a COM
application using MSXML you could use transformNodeTo Object and
transform to a stream, that way MSXML writes out a charset parameter as
needed. But with .NET you should not use MSXML at all, I doubt its
transformNodeTo Object will work with a .NET stream implementation. You
can simply run the transformation with XslTransform or
XslCompiledTran sform where the Transform method has various overloads
directly writing to a file or stream.


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 9 '06 #3
Why do you use MSXML with a managed .NET application? With .NET 1.x you
should use System.Xml.Xsl. Xsl.Transform, with .NET 2.0 ...
(We do .net 1.x) Unfortunately, we had serious performance issues with
the dotnet xslt processing libraries. When we encountered those
problems we found through some searching that we could use MSXML
instead. It has been working fine and fast, only the encoding problem
remains.

The weird thing is that MSXML called from the commandline to parse the
xslt does something different (>better) than when called with the code
posted above. The commandline call looks like this:

msxsl.exe data.xml stylesheet.xslt

Nov 10 '06 #4
Yeah; the compiled transforms in 2.0 are quite a bit better...

Without more info, I wouldn't presume to say for sure... but in a number of
cases I *have* seen, the reported performance problems between 1.1, 2.0 and
MSXML were actually more a case of a band-aid - meaning that the xslt itself
simply wasn't written very well, and the different implementations just
highlighted / exacerbated the problem - reworking some of the xslt to
included e.g. Munchean grouping can make a huge difference.

Marc
Nov 10 '06 #5
Thanks Marc, that gives hope and more incentive to switch to
studio2005/dotnet2.

As a followup on the original problem; I have been trying some new ways
to get msxml to include the charset option in one way or the other. My
latest attempt was to add this line of code...

stylesheet.crea teProcessingIns truction("xml", "version=\"1.0\ "
encoding=\"UTF-8\"");

....which did not solve my problem but still seems the way to look. So
here's a new (rather noob) subquestion, which might help me in my
current quest:

*Does anyone know of a good overview for these processinginstr uctions??*

Nov 10 '06 #6

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

Similar topics

0
2015
by: asim | last post by:
Hi All i m transforming a simple XSL file on Server side using MSXML Parser ... and writting resultant HTML directly on browser .. is there any way to get this HTML in a variable ??? i seen the article on MSDN but it makes my page blank ... plz edit my code to make is work in this manner, if possible Thankx in advance Plz Help
0
1294
by: Variable | last post by:
I have a webpage where I'm opening an XML page with MSXML, pushing it through an XSL file to generate some HTML which is incorporated into the body of the main HTML page. I have other pages where this all works great. One page, however, seems to bypass the a for-each iteration, and I can't understand why. I've used XMLSpy to validate the XML and XSL, and as far as I can see, the simulated generation through XMLSpy is correct. Here is...
1
1777
by: BCC | last post by:
Hi, I am new to msxml, and am having a hard time figuring out how to get all children of a particular node. For example, if I have something like this: <?xml version="1.0" encoding="utf-8"?> <rules> <cell id="1"> <type>CD4 Cell</type> <x>10</x> <y>10</y>
7
2095
by: Peter | last post by:
I have noticed a difference in the processing of XSL transforms between dotnet and MSXML. Dotnet formats the resulting output differently, and since we use the <pre> tag in the HTML output it makes a big difference. What is in fact correct here? I don't see that the XSL transform engine should reformat the output in this way, and would like to know if this difference is going to remain in future. The transform in question can be split...
9
1785
by: LarryR | last post by:
The following XSLT works fine using MSXML 4.0 (e.g I receive a result in about 20 seconds), but effectively hangs in both .NET 1.0 sp2 with the XML hot fix and NET 1.1. My source XML file is large at over 46,000 <atl_client> nodes <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <!-- lookup port...
7
3381
by: Michael | last post by:
Hi, I have a problem parsing XML file using XSLT stylesheet by using : using System.Xml; using System.Xml.XPath; using System.Xml.Xsl; // load Xsl stylesheet XslTransform myXslTrans = new XslTransform() ;
4
6896
by: K | last post by:
I've an XML file in UTF-8. It contains some chinese characters ( both simplified chinese and traditional chinese). In loading the XML file with MSXML parser, I used the below code to retrieve the data in a node. The CString was then display in CListCtrl. For the traditional chinese characters, they were shown correctly, but for simplified characters, I encounted many "?", but some characters were correct.
19
2607
by: Matthias Truxa | last post by:
Hello, can anyone confirm the existence of the following effects which I'd consider being a critical bug in msxml according to w3c's xpath specs? The Spec says: "The parent, ancestor, ancestor-or-self, preceding, and preceding-sibling axes are reverse axes" http://www.w3.org/TR/2005/CR-xpath20-20051103/#doc-xpath-ReverseAxis
6
7987
by: Anthony Jones | last post by:
People, Anyone else got an IIS7 server out there that they can test this little ASP file:- <% Set xml = Server.CreateObject("MSXML2.DOMDocument.3.0") xml.loadXML "<root />" Set xsl = Server.CreateObject("MSXML2.DOMDocument.3.0")
0
8459
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8367
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8889
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8650
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6206
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4202
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2781
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2017
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.