473,794 Members | 2,765 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XML Encoding question (C#)

Hi! I have the following problem:

I am getting an XML file from a 3rd party. The encoding on the XML file is
encoding="utf-8"

I have no control over generation of this file. This file is produced by a
Lotus Notes system and often has illegal characters embedded to it. Of course
the .NET XML parser produces an error.

I’ve been reading about XmlConvert.Enco deName but not sure where to apply
it. It seems to me that I can call this method once the doc has been loaded
into DOM?
But it breaks before I load the doc into DOM.

Here’s how I load the xml file:

private static XmlDocument _xmlDocument = null;

public static XmlDocument LoadAndReturnXm lDocument(strin g pstrInputFile)
{
_xmlDocument = new XmlDocument();
_xmlDocument.Pr eserveWhitespac e = false;
_xmlDocument.Lo ad(pstrInputFil e);
_xmlDocument.
return _xmlDocument;
}

What would you recommend I do to fix this problem?

Any input is greatly appreciated.
Nov 12 '05 #1
2 5248
Mike wrote:
I am getting an XML file from a 3rd party. The encoding on the XML file is
encoding="utf-8"

I have no control over generation of this file. This file is produced by a
Lotus Notes system and often has illegal characters embedded to it. Of course
the .NET XML parser produces an error.


The recommended way is to fix broken software in the first place.
Otherwise you can try to fix XML produced using non-XML tools, such regexp.
--
Oleg Tkachenko [XML MVP, MCP]
http://blog.tkachenko.com
Nov 12 '05 #2
Hi,

In your sample code you meant to write:
_xmlDocument.Lo adXml(pstrInput File); instead of _xmlDocument.Lo ad(pstrInputFil e); Right? XmlDocument.Loa d(string filename) assumes that the input is just a
url,
not the data itself.

Ion

"Mike" <Mi**@discussio ns.microsoft.co m> wrote in message
news:B0******** *************** ***********@mic rosoft.com... Hi! I have the following problem:

I am getting an XML file from a 3rd party. The encoding on the XML file is
encoding="utf-8"

I have no control over generation of this file. This file is produced by a
Lotus Notes system and often has illegal characters embedded to it. Of course the .NET XML parser produces an error.

I've been reading about XmlConvert.Enco deName but not sure where to apply
it. It seems to me that I can call this method once the doc has been loaded into DOM?
But it breaks before I load the doc into DOM.

Here's how I load the xml file:

private static XmlDocument _xmlDocument = null;

public static XmlDocument LoadAndReturnXm lDocument(strin g pstrInputFile)
{
_xmlDocument = new XmlDocument();
_xmlDocument.Pr eserveWhitespac e = false;
_xmlDocument.Lo ad(pstrInputFil e);
_xmlDocument.
return _xmlDocument;
}

What would you recommend I do to fix this problem?

Any input is greatly appreciated.

Nov 12 '05 #3

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

Similar topics

10
687
by: Christopher H. Laco | last post by:
Long story longer. I need to get web user input into a backend system that a) only grocks single byte encoding, b) expectes the data transer to be 1 bytes = 1 character, and c) uses the HP Roman-6 codepage system wide. As much as it sounds good, UTF/Unicode encoding is not an option, nor is changing the codepage. Tackling the first is easy via Encoding.Default.GetBytes and shoving it over the network. However, Encoding.Default is the...
8
2496
by: davisjoseph | last post by:
Hi All, I'm newbie to this XML world. My problem is to identify the encoding type of XML at runtime. What currently I'm doing is checking whether BOM is available in the XML; based on the BOM I'm identifying the encoding type. Here is the problem, some type of UTF-8 encoded file does'nt have BOM in the starting. So I'm identying the file as iso-8859-1 encoded which is actually encoded in UTF-8. I dont have much idea about the...
8
607
by: Demon News | last post by:
I'm trying to do a transform (Using XmlTransform class in c#) and in the Transform I'm specifying the the output xsl below: <xsl:output method="xml" encoding="UTF-8" indent="no"/> the resulting xml ends up with the following declaration: <?xml version="1.0" encoding="utf-16"?> changing the encoding to utf-16, is there something I'm doing wrong? Is it
4
8852
by: fitsch | last post by:
Hi, I am trying to write a generic RSS/Atom/OPML feed client. The problem is, that those xml feeds may have different encodings: - <?xml version="1.0" encoding="ISO-8859-1" ?>... - <?xml version="1.0" encoding="utf-8" ?>... - ... I am using the WebRequest functionality to get the feeds. So, my code
2
5071
by: velle | last post by:
My headache is growing while playing arround with unicode in Python, please help this novice. I have chosen to divide my problem into a few questions. Python 2.3.4 (#1, Feb 2 2005, 12:11:53) on linux2 1) Does " >>>print 'hello' " simply write to sys.stdout?
0
1974
by: Chris McDonough | last post by:
ElementTree's XML serialization routine implied by tree._write(file, node, encoding, namespaces looks like this (elided): def _write(self, file, node, encoding, namespaces): # write XML to file tag = node.tag if tag is Comment: file.write("<!-- %s -->" % _escape_cdata(node.text, encoding)) elif tag is ProcessingInstruction: file.write("<?%s?>" % _escape_cdata(node.text, encoding))
4
5563
by: Bob | last post by:
Hi Need to produce a Doc with no encoding info. Is there anyway of doing this? Thanks Bob i.e. <?xml version=\"1.0\" ?>
4
8382
by: Christina | last post by:
Hey Guys, Currently, I am using the below code: Dim oReqDoc as XmlDocument Dim requiredBytes As Byte() requiredBytes = System.Text.UTF8Encoding.UTF8.GetBytes(oReqDoc.InnerXml). Here, I am encoding my xml string in UTF8 format.
3
5496
by: mortb | last post by:
1. How do I determine which encoding a xmldocument or xmlreader uses when opening a document? I'm not just talking about the <?xml encoding="utf-8"?attribute, but the actual encoding of the characters in the underlying stream. 2. How do I make sure that the encoding of my created xmldocument or xmlwriter is in utf-8? Thanks! /mortb
1
32950
by: ujjwaltrivedi | last post by:
Hey guys, Can anyone tell me how to create a text file with Unicode Encoding. In am using FileStream Finalfile = new FileStream("finalfile.txt", FileMode.Append, FileAccess.Write); ###Question: Now this creates finalfile.txt with ANSI Encoding ...which is a default. Either tell me how to change the default or how to create a
0
9518
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
10433
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...
1
10161
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7538
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
6777
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
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
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2919
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.