Lost character entities using MSXML6

I load an XML file into  MSXML2.DOMDocument.6.0 object.  The XML file stores 
non-ASCII characters in Hex Code format,
so alpha α is coded as α
I save the file using xmldomSource.save but now α has been replaced with α

How do I preserve the original encoding?  

<%@ LANGUAGE = JScript %>

<%  Response.Charset= "ISO-8859-1" %>
<%  Response.Buffer= "TRUE" %>
<%  Response.Expires= -1 %>
<%
var xmldomSource = new ActiveXObject("MSXML2.DOMDocument.6.0");
		xmldomSource.preserveWhiteSpace = true;
		xmldomSource.setProperty("ServerHTTPRequest", true);
  		xmldomSource.resolveExternals = false;  
  		xmldomSource.validateOnParse = true;  
		xmldomSource.async = false;
		xmldomSource.load(Server.MapPath("input") + "\\" + "test.xml");
		 xmldomSource.save(Server.MapPath("input") + "\\" + "test_out.xml");
%>

0
Merkin (2)
10/29/2009 12:31:10 PM
dotnet.xml 7266 articles. 0 followers. Follow

4 Replies
823 Views

Similar Articles

[PageSpeed] 53

Note: "so alpha α is coded as α" should read as:
"so alpha α is coded as  &#x3b1; "

"A Merkin" wrote:

> I load an XML file into  MSXML2.DOMDocument.6.0 object.  The XML file stores 
> non-ASCII characters in Hex Code format,
> so alpha α is coded as α
> I save the file using xmldomSource.save but now α has been replaced with α
> 
> How do I preserve the original encoding?  
> 
> <%@ LANGUAGE = JScript %>
> 
> <%  Response.Charset= "ISO-8859-1" %>
> <%  Response.Buffer= "TRUE" %>
> <%  Response.Expires= -1 %>
> <%
> var xmldomSource = new ActiveXObject("MSXML2.DOMDocument.6.0");
> 		xmldomSource.preserveWhiteSpace = true;
> 		xmldomSource.setProperty("ServerHTTPRequest", true);
>   		xmldomSource.resolveExternals = false;  
>   		xmldomSource.validateOnParse = true;  
> 		xmldomSource.async = false;
> 		xmldomSource.load(Server.MapPath("input") + "\\" + "test.xml");
> 		 xmldomSource.save(Server.MapPath("input") + "\\" + "test_out.xml");
> %>
> 
0
AMerkin (2)
10/29/2009 12:57:01 PM
A Merkin wrote:
> I load an XML file into  MSXML2.DOMDocument.6.0 object.  The XML file stores 
> non-ASCII characters in Hex Code format,
> so alpha α is coded as α
> I save the file using xmldomSource.save but now α has been replaced with α
> 
> How do I preserve the original encoding?  
> 
> <%@ LANGUAGE = JScript %>
> 
> <%  Response.Charset= "ISO-8859-1" %>
> <%  Response.Buffer= "TRUE" %>
> <%  Response.Expires= -1 %>
> <%
> var xmldomSource = new ActiveXObject("MSXML2.DOMDocument.6.0");
> 		xmldomSource.preserveWhiteSpace = true;
> 		xmldomSource.setProperty("ServerHTTPRequest", true);
>   		xmldomSource.resolveExternals = false;  
>   		xmldomSource.validateOnParse = true;  
> 		xmldomSource.async = false;
> 		xmldomSource.load(Server.MapPath("input") + "\\" + "test.xml");
> 		 xmldomSource.save(Server.MapPath("input") + "\\" + "test_out.xml");
> %>

I am afraid you have posted through the web interface as that way any 
attempt to post code samples with numeric character references or entity 
references fails to show them.

But generally the DOM model does not store character reference so when 
you load an XML document with a character reference e.g. & # 1 6 0 ; 
(without any spaces) then the XML parser decodes that numeric character 
reference into the corresponding character and the DOM model simply has 
a text node with that character and no information that the original 
source contained a numeric character reference. Consequently, when you 
save the DOM model back, the character reference is not preserved.

-- 

	Martin Honnen --- MVP XML
	http://msmvps.com/blogs/martin_honnen/
0
mahotrash (1778)
10/29/2009 12:59:24 PM
A Merkin wrote:
> Note: "so alpha α is coded as α" should read as:
> "so alpha α is coded as  &#x3b1; "

The DOM model does not _not_ preserve numeric character references. The 
XML parser replaces any character reference with its character which the 
DOM stores and upon saving the DOM back you will get the character 
stored, not a reference to it.

-- 

	Martin Honnen --- MVP XML
	http://msmvps.com/blogs/martin_honnen/
0
mahotrash (1778)
10/29/2009 1:41:14 PM
Thanks Martin,

Not exactly what I wanted to hear and I'm surprised I haven't encountered 
this before. I load the XML into a DOM so I can add remove and update various 
nodes. It looks as though I will need to run the result of this through an 
XSLT transform to recover the character references as our typesetters will 
reject this XML. I have a style sheet that will do this. Yet another layer of 
complexity! It's a shame this behaviour can't be avoided.    

"Martin Honnen" wrote:

> A Merkin wrote:
> > I load an XML file into  MSXML2.DOMDocument.6.0 object.  The XML file stores 
> > non-ASCII characters in Hex Code format,
> > so alpha α is coded as α
> > I save the file using xmldomSource.save but now α has been replaced with α
> > 
> > How do I preserve the original encoding?  
> > 
> > <%@ LANGUAGE = JScript %>
> > 
> > <%  Response.Charset= "ISO-8859-1" %>
> > <%  Response.Buffer= "TRUE" %>
> > <%  Response.Expires= -1 %>
> > <%
> > var xmldomSource = new ActiveXObject("MSXML2.DOMDocument.6.0");
> > 		xmldomSource.preserveWhiteSpace = true;
> > 		xmldomSource.setProperty("ServerHTTPRequest", true);
> >   		xmldomSource.resolveExternals = false;  
> >   		xmldomSource.validateOnParse = true;  
> > 		xmldomSource.async = false;
> > 		xmldomSource.load(Server.MapPath("input") + "\\" + "test.xml");
> > 		 xmldomSource.save(Server.MapPath("input") + "\\" + "test_out.xml");
> > %>
> 
> I am afraid you have posted through the web interface as that way any 
> attempt to post code samples with numeric character references or entity 
> references fails to show them.
> 
> But generally the DOM model does not store character reference so when 
> you load an XML document with a character reference e.g. & # 1 6 0 ; 
> (without any spaces) then the XML parser decodes that numeric character 
> reference into the corresponding character and the DOM model simply has 
> a text node with that character and no information that the original 
> source contained a numeric character reference. Consequently, when you 
> save the DOM model back, the character reference is not preserved.
> 
> -- 
> 
> 	Martin Honnen --- MVP XML
> 	http://msmvps.com/blogs/martin_honnen/
> .
> 
0
AMerkin (2)
10/29/2009 3:38:01 PM
Reply:

Similar Artilces:

How do we use lookup ?
I have a table of values like this from A1 to B4 A B 1 123 wall 2 254 chair 3 389 book 4 478 pen Now I want to write a function (maybe with "lookup") to look at the first tree characters in coloum A and return the value of it (here, writen in coloumb B) I have tried with this: A B C 1 123 wall =lookup(left(A1;3);A1:B4;2) 2 254 chair 3 389 book 4 478 pen but I get #N/A in C1 if I write =lookup(123;A1:B4;2) I get 2 where as I would like to get "wall" I have also tried with =VLOOKUP(123,A1:B4,2,FALSE) i...

Lost Formatting When tab is copied
My problem would seem to be very basic. I have a table that has values with dollars in columns and then a rate (i.e. one cell less another and then divide) in percentage format. When I copy an existing tab either into the same workbook or into a new workbook, many of my percent formats change to dollar format. This happens no matter what page I copy and it happens on pages that I am not even touching or copying. Often times these cells that lose their formatting are next to cells that are in dollar format that are pulling their data from pivot table. Could this have anything to do with it? ...

Public Folders using Outlook 97
We have several users still using Windows 98 running Office 97 connected to our Exchange server in Windows SBS 2003 server. How do I get the public folders to show up in this older version of Outlook? Thanks Ron If the user has permission to view the folders, they should appear in = the Folder List.=20 --=20 Sue Mosher, Outlook MVP Author of Microsoft Outlook Programming - Jumpstart for=20 Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx "Ron Boetger" <rboetger@bblink.net> wrote in message = news:9je3511te7i986ampmsb8t...

What was lost is found
Some of you may recall my frantic thrashing around here when I reinstalled my OS (Win XP) and had to reinstall Publisher 98 but could not find the installation disk. With a tweak here and a cludge there I was able to reinstall from the Publisher directory on the drive. (Don't ever install to the Windows/Program Files directory. Give each application its own root directory.) But the reinstall, though good enough to retrieve all my *.pub files and create new ones, lacks a few features, like hyphenation, spellcheck, etc. But today, what was lost is found. The installation disk turned ...

can I use a CArchive with a CSocket to read regular text?
if so which type do I use in the CSocket OnReceive function: ar >> char* didn't work thanks CArchive can only interpret things that were written by CArchive. Even text. To receive plain text just pass the text buffer to Read. -- Scott McPhillips [VC++ MVP] thanks! Scott McPhillips [MVP] wrote: > CArchive can only interpret things that were written by CArchive. Even > text. To receive plain text just pass the text buffer to Read. > > -- > Scott McPhillips [VC++ MVP] ...

2005 Deluxe
Upgraded from 2003. Seems like I've lost functionality. Can't find how to separate catagory entry between category and subcategory (all one entry now). Also can't find the MoneySide FollowUP Notes that I used to have on the home page. Am I not looking in the right place? Thanks. MoneySide has been gone since M04. You are, IIRC, the second person to post here having noticed. As to dual cat lists: see http://umpmfaq.info/faqdb.php?q=161. BTW, you are supposed to prefer single list. "Elliot" <Elliot@discussions.microsoft.com> wrote in message news:E9082426-5...

lost save file
I had a hard drive crash....was able to retrive everything from outlook express except my "SAVE FOLDERS"....I'm sure they are there...any ideas where I should look or what I need to do???? I really need the folders. Thanks Search for .eml files . . . . . "Tink" <Tink@discussions.microsoft.com> wrote in message news:468CD94A-33D3-45C1-8F1E-1DD5ADC164F2@microsoft.com... > I had a hard drive crash....was able to retrive everything from outlook > express except my "SAVE FOLDERS"....I'm sure they are there...any ideas > where...

why does error 0x8007000E occur when receiving emails using outloo
currently when i use outlook for email for my business email address of aemerson@leggettaustralia.com.au i receive error message 0x8007000E saying my system is out of memory or system resources, and i should close other applications although i do not have other applications open. this error message only started to occur on friday 3rd march, before that outlook was working fine. i know i have receivied new emails but until i fix this issue outlook will not download them from the bigpond server. can someone please help me fix this problem. Alan Emerson <Alan Emerson@discussions.micr...

Word 2007 (on Vista) crashes when using CreateObject in VBA
Can anyone help with this? I think it may be the config of my laptop, but don't know what specifically. I'm trying to open an app in VBA using CreateObject but Word crashes every time with a 'Microsoft Office Word has stopped working' message. Sample code here:- Sub excelcalltest() Dim objExcel On Error GoTo Err Set objExcel = CreateObject("Excel.Application") - it crashes once it gets to this line objExcel.Visible = True Err: MsgBox Err.description End Sub I'm not a programmer but know basics. I don't need anything ticked in Tools/Referen...

Counting multiple cells using a criteria
I am trying to count the number of times "c" appears in a column but I need to limit the count using a second criteria found in another column Try something like this... =SUMPRODUCT(--(A1:A100="c"),--(B1:B100="x")) If 'x' is a number, remove the quotes. Hope this helps! In article <F71A7941-FF3D-4907-B14F-9F1A4E6C5049@microsoft.com>, "John" <John@discussions.microsoft.com> wrote: > I am trying to count the number of times "c" appears in a column but I need > to limit the count using a second criteria found in ...

Lost Outlook email
----------------------------------------------------------------------- A poll associated with this post was created, to vote and see th results, please visit http://www.outlookforum.com/forums/showthread.php?threadid=5370 ----------------------------------------------------------------------- Question: Am I hosed - YE - PROBABL - MAYB - N ----------------------------------------------------------------------- I downloaded my email from the server, got a message that some of th rest of my mail couldn't be retrieved, closed outlook, re-opened it and the messages I had already retrieved ...

apostrophe is replaced by other characters in replies
If a user receives an email, then replies to it any apostrophes (') in the reply get changed to an a with a carat over the top of it which is a latin lower case A, then a Euro symbol, then the small TM for trademark. Only certain users are seeing this. I'd think it is due to a formatting or font problem, but all users are using standard machines. Any ideas? ...

Using Drop Down box that can be edited
Hi, I have created a form in Word 2007, but would like to have the drop down box I created to also be overwritten by the user if the items in the drop box doesn't include their choice. Thanks fjcunninghamjr One possibility would be to replace one of the items in the list with a user input item. You could do this with a macro run on exit from the dropdown field Assuming the dropdown field Dropdown1, put an item at the end of the dropdown list "Enter your own value" then run the following macro on exit from that field Dim sChoice As String Dim fDD As FormFie...

Lost security on modified reports
It appears that access has been lost to modified reports. I checked security and access to the appropriate modified reports is selected, but I can not access them, nor can other users. We work in a Citrix environment and all users access the forms and reports from the server, not local workstations. I have unmarked and marked access and logged out and back in, but with no luck. Any suggestions? Have you tried using Advanced Security's Verify Security feature to check that all the security records are correct, valid and undamaged? It is worth a try. PS: You can also use Advan...

xmlTextWriter: process can't access file 'cos it's being used by another process
hiya, I have been reading thru previous posts but I still can't work this out. I keep the IDE closed during execution, so I can rule out that possibility. I have a generic static (shared) function for my XSLT transforms. This function: 1) accepts an XMLDoc and XSLTDoc as args 2) returns a streamReader Intermittently, I get the error at this line: <code> Dim writer As XmlTextWriter = New XmlTextWriter(sourceXmlDoc, Nothing) <\code> here is the snipped function: <code> Public Shared Function TransformTheDoc(ByVal sourceXmlDoc As String, ByVal xsltDoc As String) As Stre...

Using Nicknames for Salutations
I am trying to create a mailmerge document and need the salutation to read ie, Dear Jack when a first name is John or Dear Jan when the first name might be Janet. I put the salutation in the nickname field of the Outlook 2002 contact file, however, I don't seem to be able to find the nickname field when doing a mail merge. Any thoughts? Bob ...

Can I use MS Groove with my Macbook?
I have students using Groove for their graduate team work and the Mac users are struggling to stay up in my classes. Any advide about the Mac interface with Groove 2007 issues? You will get better results by posting to the groove newsgroup directly On the web: http://www.microsoft.com/communities/newsgroups/list/en-us/default.aspx?dg=microsoft.public.groove -- Peter Please Reply to Newsgroup for the benefit of others Requests for assistance by email can not and will not be acknowledged. http://www.microsoft.com/protect "Grooving Professor" <Grooving Profe...

lost portfolio dat
i logged onto msn money to check a portfolio and its gone. i saved the data previously, how do i recover it? In microsoft.public.money, mark wrote: >i logged onto msn money to check a portfolio and its >gone. i saved the data previously, how do i recover it? You saved it as *.inv or "my portfolio Backup.mbf"? The group for MSN Money is microsoft.public.moneycentral. ...

Make a greenbar page in Excel using Conditional Formatting
Someone told me you can use Format/Conditional Formatting and selectin the Formula is criteria to create a worksheet in which every other ro is shaded. I can't seem to do it. Can anyone help -- Message posted from http://www.ExcelForum.com Chip Pearson shows how here: http://www.cpearson.com/excel/banding.htm <-*-><-*-><-*-><-*-><-*-><-*-><-*-><-*-> Hope this helps! Anne Troy (better known as Dreamboat) Author: Dreamboat on Word Email: Dreamboat*at*Piersontech.com Web: www.TheOfficeExperts.com <-*-><-*-><-*-><-*->&...

Using DCount with WHERE criteria
My main form holds patient information (tblPatients), and my subform holds daily information (tblDailyData) collected for each patient. (Hence, a one-to-many.) An individual patient should not have the same date entered twice, so on the subform, in the BeforeUpdate event of the date control, I need to check for a duplicate date. Right now my code looks like: If DCount("DailyDate", "tblDailyData", "DailyDate= #" & Me.DailyDate & "#") > 0 Then Me.Undo MsgBox "Sorry! This date has already been entered.", vbExclamation, "...

Getting past the Worksheet Name character limit?
Excel 2 Is there any way to get around (or remove) the limit on characters that can be used to name a worksheet? We are trying to get our licenses in a spreadsheet and want to name each sheet with the name of the software. It seems there's a 31 character limit which is not enough for what I need Is there any wya to remove this limit or increase it or anything like that Thanks. Hi AFAIK there is no way beyond this Excel limit -- Regards Frank Kabel Frankfurt, Germany Mr B wrote: > Excel 2k > > Is there any way to get around (or remove) the limit on characters > that can ...

Enter chinese characters in Microsoft Great Plains
Hi Everyone! Does anyone knows if chinese characters is already supported in Great Plains? The last time I checked, it is not yet supported. I was able to do some testing and research and found a software that will enable users to key in chinese characters anywhere in MGP as long as it accepts alphabets. However, it is costly to the client's part as they would need to purchase this software. For cost saving purposes, is there a built in product or is there any way that would allow users to enter chinese characters. My client is in Singapore and most of my client's request ...

formula to replace cell with over 8 characters with word LAN
Hello Group, I hope someone will be able to help. I need a formula that can check each cell in column "D" and if it has over 8 characters in the cell, return a value of the word LAN in column "F". Anything with 8 or under should remain as is. There will be up to 600 row entries in column "D". example of col: 799Z 777X 79BM 08/30/06(An) 08/30/06(Put) 08/30/06(InT) 76CC I'm aware that with all the talent and expertise in the group, this is small potato's, but it is greatly appreciated. Thank you, Calop ?... =IF(LE...

lost folders
A friend whose computer runs WinXP fully updated just lost her Outlook Express Inbox, Drafts, and Sent Items folders. She says it happened after this week's Automatic Update. She found the Inbox and Drafts in her Recycle Bin, but her Sent Items folder seems to have disappeared. She hadn't overloaded any of the folders. There were 38 messages in Sent Items. I had her check her Store folder just to make sure, and there is no Sent Items folder there. Prior to the update, and now as well, she has been getting a large number of messages wanting to compact her OE folders. Th...

lost authenticity number
I cannot find my authenticity number for my disk. Is there any way to get the number off of my computer? If you mean your Product Key, you can call Micorosft for it. I'm assuming you have to reload Publisher? -- JoAnn Paules MVP Microsoft [Publisher] "Amy Gentzyel" <anonymous@discussions.microsoft.com> wrote in message news:1ecd01c48d27$cfcdaba0$a601280a@phx.gbl... >I cannot find my authenticity number for my disk. Is > there any way to get the number off of my computer? --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://w...