Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Difference between transformNode and transformNodeToObject with respect to character encoding

From: "Pramod Subramanyan" <pramod.sub@-----.--->
To: NULL
Date: 1/6/2007 6:02:00 AM

Hi,

Yesterday I had an interesting bug in a piece of code that applied a
stylesheet to a XML document. The input document used some "special"
characters (specifically the symbol for micro - which was specified in
the input XML as &#181;). The stylesheet was being used to convert the
input XML to Excel's SpreadsheetML. To make a long story short, the
micro used to disappear when viewed from XML.

We we using ActiveX and MSXML 4.0.

We spent almost half a day trying to figure out what was going wrong,
and finally tracked it down the code that applied the stylesheet - the
buggy code used to look like this

...
outXMLString = inputDoc.transformNode(stylesheet)
' Code to write outXMLString to a file
...

The input XML was something like this: (The micro was being used as in
the unit Micro Amperes)

<Stuff>
<Data>
&#181;A
</Data>
</Stuff>

And the XSLT was something like this:

...
<xsl:value-of select="./Data" />
...

The problem was that the &#181; used to come out as a single character.
(A lot of digging around revealed that you need two characters to
represent micro - C2 B5 rather than just B5 - btw B5 is 181 represented
in hex) Some applications - like Excel - would just pretend that the
character wasn't there. Some others - like Visual Studio, Firefox would
show a helpful little question mark instead of the character - and some
others - like VIM would actually render it as micro.

Me not knowing too much about character encodings - having dealt with
ASCII all my life - was about as confused as I could. But after trying
this, that and everything else, with thanks some kind hearted souls on
Usenet, found that changing the code that applied the stylesheet to
look like this:

...
inputDoc.transformNodeToObject(stylesheet, outputDoc)
outputDoc.save(filename)
...

would fix the problem.

My question to any wise and helpful souls out there is pretty simple:
Why does this work, while the old one doesn't? My current guess is that
this has something do with how the string coming out transformNode is
encoded, but I don't really understand the details.

Can you guys help out please?



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent