|
-
Saved .XML file contains 
 in place of Carriage Returns and line feeds.
I am perplexed with the resulting .XML file that is modified from my C#.NET code below.
Code:
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.PreserveWhitespace = true;
xmlDoc.Load(metabasePath + "MetaBase.xml");
XmlElement virDir = xmlDoc.SelectSingleNode("//*[local-name()='IIsWebVirtualDir'][@Location='/LM/W3SVC/1/ROOT/EnterpriseCRM']") as XmlElement;
if (virDir != null) {
virDir.SetAttribute("Location", "/My/New/stupid/LocationAttribute/PieceofGarbage"); //not a real VirDir, just for testing)
xmlDoc.Save(metabasePath + @"RicksNewXMLDocument.xml");
}
When I open the new Metabase.XML file with notepad, I find that the tabs have been changed to spaces, and in place of my Carriage returns and line feeds, I see 
 which appear to me to look like hex representations of what the white space characters should be.
So just to make sure it wasn't something I had done in my code that modified the attribute, I copied the original file back over, then I ran the following, which as you can see, simply opens the original file, sets the XMLDocument.PreserveWhiteSpace property to true, and then saves it right back out.
Code:
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.PreserveWhitespace = true;
xmlDoc.Load(metabasePath + "MetaBase.xml");
xmlDoc.Save(metabasePath + "xmlDoc_Save_MetabaseXML.xml");
I got the same results. So, I opened up the before and after files with a Hex editor and noticed that both files have a Byte-Order-Mark of EF BB BF, which I understand to be UTF8. So i closed both of the files and this time I tried using an XMLWriter object, along with an XMLWriterSettings object to specify the encoding:
Code:
XmlWriterSettings settings = new XmlWriterSettings();
settings.Encoding = new UTF8Encoding(true); // Passing false to UTF8Encoding means, do not emit the BOM.
using (XmlWriter w = XmlWriter.Create(metabasePath + "XMLWriter_MetaBase.xml", settings)) {
xmlDoc.Save(w);
}
I got the same 
 for CR/LF again, as well as, now the file is about 11KB larger, and there are a ton of these everywhere: 	 which appear to be in place of TAB characters, (except it looks like that there are still a few tabs in the document that have been changed to a plain space).
This is driving me nuts. I have thought about slitting my wrists, but I only have an electric Norelco. What am I doing wrong here? I would very much appreciate any help you can give me on this. (For reference, I created this with using Visual Studio 2010 Pro (WinForm App), .NET 3.5, Windows 7 64-bit)
-Rick
Similar Threads
-
By Peter_APIIT in forum C++
Replies: 3
Last Post: 06-24-2007, 04:08 AM
-
By David Chu in forum .NET
Replies: 6
Last Post: 08-16-2006, 10:32 PM
-
By sashi1977 in forum .NET
Replies: 1
Last Post: 08-24-2005, 08:14 AM
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks