473,406 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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.EncodeName 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 LoadAndReturnXmlDocument(string pstrInputFile)
{
_xmlDocument = new XmlDocument();
_xmlDocument.PreserveWhitespace = false;
_xmlDocument.Load(pstrInputFile);
_xmlDocument.
return _xmlDocument;
}

What would you recommend I do to fix this problem?

Any input is greatly appreciated.
Nov 12 '05 #1
2 5230
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.LoadXml(pstrInputFile); instead of _xmlDocument.Load(pstrInputFile); Right? XmlDocument.Load(string filename) assumes that the input is just a
url,
not the data itself.

Ion

"Mike" <Mi**@discussions.microsoft.com> wrote in message
news:B0**********************************@microsof t.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.EncodeName 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 LoadAndReturnXmlDocument(string pstrInputFile)
{
_xmlDocument = new XmlDocument();
_xmlDocument.PreserveWhitespace = false;
_xmlDocument.Load(pstrInputFile);
_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
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...
8
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...
8
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...
4
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...
2
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) ...
0
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...
4
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
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...
3
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...
1
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); ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.