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
1858 Views

Similar Articles

[PageSpeed] 21

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 (1777)
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 (1777)
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:

Lost message
I just had a user send an internal e-mail to 5 recipients and only 4 received it. I could not find it in any folder in the 5th user's Outlook, including spam. I opened the message from the original sender's Sent folder and Resent it successfully to all 5 people. It also was not in the Exch Svr's Spam folder (ScanMail eMgr), nor stuck in a queue. Running Exch 5.5 SP4 on NT4 SP6a. All users are Win2K-Pro SP4 and Office 2K, various SPs. About 50 users on the LAN - extremely smooth running otherwise. The Exch Svr is sometimes pushed to it's limit, only 600Mhz and 768Mb ram. IS is ...

Which one uses less memory?
I have two ways to use connection with sqlcommands. here is sample codes in C#: The Way First: DataSet ds = new DataSet(); SqlConnection conn = new SqlConnection(" .... "); conn.Open(); SqlDataAdapter da = new SqlDataAdapter("select * from table1", conn); da.Fill(ds, "table1"); da.SelectCommand.CommantText = "select * from table2"; da.Fill(ds, "table2"); da.SelectCommand.CommandText = "select * from table3"; da.Fill(ds, "table3"); Conn.Close(); The Way Second: DataSet ds = new DataSet(); SqlConnection conn =...

How to use different imagelist in header control and CListView?
Hi I recently encountered this problem. I have set one imagelist to the header control and another imagelist to the CListView. Later I found that the imagelist of the header control is changed to the one I set for the CListView. After some debugging, I realized that whenever I set imagelist to CListView, the Header control imagelist will be set to the same as its parent (CListView). I am able to prevent the setting of imagelist to the header control for CListCtrl. But for the CListView, I do not know how. Does anyone has the solution for this issue? Appreciate your help. Thanks. Tham...

losts tasks again
They could possibly store your tasks (ext .msg) in C:\WINDOWS\Local Settings\Application Data\Microsoft\Outlook\archive.pst ...

lost margin bar
i DON'T KNOW HOW IT HAPPENED BUT I NO LONGER HAVE A MARGIN BAR IN WORD??? WHAT HAPPENED??? Are you referring to the ruler bar? View | Ruler should bring it back. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA http://word.mvps.org "Carolyn" <Carolyn@discussions.microsoft.com> wrote in message news:F19FB867-E36D-428E-A5B9-CFEEB9FBFF74@microsoft.com... >i DON'T KNOW HOW IT HAPPENED BUT I NO LONGER HAVE A MARGIN BAR IN WORD??? > WHAT HAPPENED??? > ...

Using Outlook 2007
I have just installed Office 2007. I prefer to have my emails sent to my user account rather than the Administrator account. Outlook has to be configured in the Admin a/c and works OK but when I try to generate it in my User a/c I get the error message that it cannot connect - is this because of conflict with the Admin a/c? Any suggestions? -- Steve Nr Malvern UK ...

Using the Euro symbol
I have an Access front end to a SQL Server 2005 database using ODBC linked tables. There appears to be a problem when using the euro symbol in queries. SELECT * FROM tbl_Datatable WHERE (tbl_Datatable.strPRICE)='?40'; This query returns nothing although there are many entries with a strPRICE of '?40' SELECT * FROM tbl_Datatable WHERE (tbl_Datatable.strPRICE)='$40'; This query returns all with a strPRICE of '$40' How do I use the symbol in queries? Regards Colin Col wrote: > I have an Access front end to a SQL Server 2005 database using ODBC lin...

Cell borders lost with cut
We have developed a time sheet in Excel 2002 (Windows XP) and used heavy borders around time input cells. When users move entered time values using cut, rather than copy, the borders are removed. Is there a way to maintain the cell borders when using cut? Thanks "Brinton Ramoly" <anonymous@discussions.microsoft.com> wrote in message news:08c401c3c572$5477b220$a301280a@phx.gbl... > We have developed a time sheet in Excel 2002 (Windows XP) > and used heavy borders around time input cells. When users > move entered time values using cut, rather than copy, the > bo...

lost here...
I have a problem with my Outlook. I feel dumb that I can't fix it. I am missing the headers in my reading pane. Not missing them when I print... just missing them in the reading pane. I have tried to start Outlook with the /safe switch but it didn't help. I have Outlook 2003, IE6(if that matters) and XP. My system is fully patched. I think this problem happened when I applied the patches yesterday or when I installed the conversion tools for Office (to allow me to read 2007 documents, etc...). Has anyone had this problem or is there a checkbox I am missing somewhere? TI...

Additional Users on Entity
Many times I have had a need to attach an additional CRM user to a contact record (or account). ie; I have a record owner that might be the Loan officer in a mortgage company. In addition I need to track who the loan processor is (and be able to automate a reminder to them from workflow). Then maybe the internal Funding agent... I would be great to be able to have the non-owners attached to the record. Just a simple dynamic dropdown list. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this sugge...

Outlook News gets lost
Here's a kooky problem. I tried clicking on "News" in Outlook 2003, one of the options at the top of the screen. Worked fine. Next day, it broke, displayed the contents of a Windows folder. Out of curiosity, I went to Control Panel -- Internet Options -- Programs, and saw that the entry next to News was blank. I selected Outlook Express as my newsreader (Outlook alone was not on the drop-down menu). I saved the changes, went back to Outlook, "News" worked fine. Next morning, lo and behold, it didn't work. Back to Control Panel stuff, and once again, th...

most recently used list
Hello: I would like to have a group of people to have access to everything in the worksheet and another group to to be able to edit just one column and view the rest. I tried to use Allow Users to Edit Ranges but it does not seem to take effect. Can you help? Thanks. -- danka My previous question's subject was to be Cell/column permission protection. I am not sure if I can modify posted message. "danka" wrote: > Hello: > > I would like to have a group of people to have access to everything in the > worksheet and another group to to be able to edit jus...

Blocking specific character sets with IMFv2
How can I block specific character sets (ie cyrillic or asian) with IMFv2? Thanks! That functionality is not provided with IMF (v1 or 2). Many 3rd party anti-spam apps do this. -- Bharat Suneja MCSE, MCT www.zenprise.com blog: www.suneja.com/blog ----------------------------------------- "Fritz" <fritz@dontbite.com> wrote in message news:e2mxTU5QGHA.4696@tk2msftngp13.phx.gbl... > How can I block specific character sets (ie cyrillic or asian) with IMFv2? > > Thanks! > Any idea if it'll be available in the next version of IMF? I mean, the idea of r...

Service entity.
Hi Is there a way to associate a service with a contact line, I used products for services but I still want some kind of association. I tried using a custom entity to link the contract with services but didn't work either. I know that modifying system entities or adding new relations to predefined system entities is not supported. Thanks ...

Outlook 2003 will not use Word 2003 as email editor
I have a user that cannot use Word 2003 as her email editor. When she is in Outlook and tries to create a new message she gets an error message that says Outlook cannot use Word as the email editor as it is not the same version as Outlook. Both Outlook and Word are version 2003 installed at once from an Office 2003 Volume lincese CD on a brand new computer. Other users are not experiencing this problem. Any suggestions? I have tried Detect and Repair and have opened Word and use send to just fine but she just can't get Outlook to open Word as the email editor. Thanks! Kent ...

lost data....lost person!
I'll try to keep it simple....I have Windows XP Home Edition...and The Office 2000 suite....I was useing the Excel 2000 program and forgot to save the data, however, I DID NOT close the program. The data I had put in was gone when I went back to do some more entries and save and close the workbook. When I tried undo in the edit menu it said that I Couldn't undo and only after switching from sheet to sheet did it finally show that I could do one undo but it was on a seperate sheet than the one that I had showing when the option was available and I believe that it was informat...

Outlook 2003 on MCE using local user to auth against Exchange 2003
Hi, a user here is running MCE (thus NOT on the domain) and he's trying to connect with Outlook 2003 to an Exchange 2003 (RPC, NOT over HTTP). If he sets the check on "Always prompt for user name and password" he'll be asked multiple times to enter his Ex- change (domain) account once a while. As this is MCE, he can't store these credentials. This is quite annoying, that Outlook doesn't store these credentials at least for the time it's running. When the check is removed, Outlook always uses his local user account (HOSTNAME\LOCAL USER) to authenticate against ...

What template does word use when creating emails for Outlook 2003
I want to be able to edit the .dot file that word uses to control the formatting when sending emails in Outlook 2003. What is it called and where can I find it please? Thanks rfc rfc <rfc at richardcooke.co.uk> wrote: > I want to be able to edit the .dot file that word uses to control the > formatting when sending emails in Outlook 2003. What is it called > and where can I find it please? My testing indicates that Outlook 2003 using Word for the editor uses Normal.dot for the template. -- Brian Tillman Thank you, I know at least in part this is correct. What wo...

Setting up/using Analytical Acctg.
I have what I think is a very simple requirement. The client wants to be able to track jobs. Specifically he wants to be able to run a report and see how much money he made or lost on a particulr job. Now this seems like a pretty straightforward and simple use of AA to me, but it seems that simple still does not mean easy. I set up AA with a single Trx dimension (JOBS), and assigned Transaction Dimesion Codes (JOB01, JON02, etc). I can post POs and Saels Invoices, distribute amounts to the various jobs, and the Posting Journals (and AA porting journals) show all the correct amounts. ...

Using Chart Wizard
Hello from Steved ='Period.3-06'!$F$5:$J$5,'Period.3-06'!$F$25:$J$25,'Period.3-06'!$F$90:$J$90 Question I have labeled the next sheet Period.2-06 ='Period.3-06'!$F$5:$J$5,'Period.3-06'!$F$25:$J$25,'Period.3-06'!$F$90:$J$90, +'Period.2-06'!$F$5:$J$5,'Period.2-06'!$F$25:$J$25,'Period.2-06'!$F$90:$J$90 it is giving me "The Formula You Typed Contains An Error. This is my first attempt at doing graphs. What Have I not done Correctly Please. Thankyou. Hello from Steved the answer is =SERIES("Accident At Fault&qu...

Lost Contacts #6
I am running Office 2003. My contacts list shows up in my Personal Folder but when I click on on Contacts, all of my contacts show up. When I try to send and e-mail, however, and click to add a contact address to my e-mail, I am told that there are no entries in my address book. How can I recover my contacts? Clearly your Contacts are in place, what has occured however is the the Contacts are not shown as an Address Book (which is a filtered view of your Contacts) http://support.microsoft.com/kb/287563 "Guy Delaney" <delaney@suddenlink.net> wrote in message news:evo...

Could use some help after crash
My computer crashed (turned out to be my mother board) and I have numerous back ups (.mny) (from cd and floppy) that I've tried to install on my new computer and every one of them want's a password. One of my files did have a password and I know FOR SURE i'm entering the right one and its still not working. I've tried installing to Money 2000 (the original one i had) and 2006 which the new computer has. Neither seems to work at all. I need this info for taxes and don't EVEN want to try to re-create it can anyone help with this? Thanks in advance for ANY help. Cheryl ...

avoiding use of UpdateData() and GetdlgItem() with radiobuttons ???
The suggestions made by J.M. Newcomer in his articles ( http://www.flounder.com/mvp_tips.htm#Avoiding%20UpdateData http://www.flounder.com/getdlgitem.htm ) not to use UpdateData and GetDlgItem in a Singele Dialog Apllication sound very convincing to me. And I would like to make it so in my future mfc-coding. ONLY: Since I am a real newbie I can not figure out a way to avoid it when using RadioButtons. In his article Newcomer says that I would have to set the WS_GROUP flag for each and every radiobutton. This seems rather strange to me, because then each Radiobutton has its own group. Als...

lost emails
I just lost 3 months of emails from my inbox. I have everything before 12/3/2009 and I seem to have recent messages from 3/25/2010. All the in between are gone. They disappeared at one moment a few days ago. Any idea of how that can happen and if there is any way for me to get them back? Help Huck The two most common reasons for what you describe is disruption of the compacting process, (never touch anything until it's finished), or bloated folders. More on that below. Why does OE insist on compacting folders when I close it?: http://www.insideoe.com/faqs/why...

SSMS SQLCmdMode and USE
I am trying to loop over some database names and apply scripts to each DB. I thought this would work...but as soon as i introduce the USE command i get and error reported on the :setvar p @db; command. Connecting to .\sql2005... Msg 102, Level 15, State 1, Line 18 Incorrect syntax near '@db'. Disconnecting connection from .\sql2005... If i take the use out it works fine but now i can't run the scripts on each database. The use can be done this way because a simple :setvar db and subsequent use $(db) will work. Perhaps it is the USE in the loop? thanks danny :s...