473,698 Members | 2,080 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Illegal Characters in XML document

Hi,

I'm using the XmlTextReader to read a badly formatted XML document from a
URL (it has no <?xml tag) on a remote website (not mine). About halfway
through, I get an Illegal Character exception, which I'm assuming means that
the default encoding type is wrong.

Does anyone know a way to override the encoding type on the XmlTextReader?

Thanks in advance,

Duncan

Nov 16 '05 #1
2 7584
Duncan Welch <du**@ntpcl.f9. co.uk> wrote:
I'm using the XmlTextReader to read a badly formatted XML document from a
URL (it has no <?xml tag) on a remote website (not mine). About halfway
through, I get an Illegal Character exception, which I'm assuming means that
the default encoding type is wrong.

Does anyone know a way to override the encoding type on the XmlTextReader?


Well, you could download the document and then use a StreamReader to
convert the encoding. That might not be the problem though - it might
be something like a < within text (instead of &lt;). I'd try to look at
the place where the error occurs to check before going to too much
other trouble.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
The default encoding type on the XmlTextReader is UTF-8, if no encoding type
is specified in the xml file.

Try this to change the default encoding type

//open a file stream
FileStream fstream= new FileStream(@"c: \myXml.xml, FileMode.Open,
FileAccess.Read );

//initialize a XmlParsercontex t and specify the encoding type
XmlParserContex t myParserContext = new XmlParserContex t(null, null, "",
XmlSpace.Defaul t, System.Text.Enc oding.UTF7);

//init XmlTextReader
XmlTextReader xtr = new XmlTextReader(f stream, XmlNodeType.Doc ument,
myParserContext );

--
Shak
(Houston)
"Duncan Welch" <du**@ntpcl.f9. co.uk> wrote in message
news:eX******** *****@TK2MSFTNG P10.phx.gbl...
Hi,

I'm using the XmlTextReader to read a badly formatted XML document from a
URL (it has no <?xml tag) on a remote website (not mine). About halfway
through, I get an Illegal Character exception, which I'm assuming means that the default encoding type is wrong.

Does anyone know a way to override the encoding type on the XmlTextReader?

Thanks in advance,

Duncan

Nov 16 '05 #3

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

Similar topics

1
2284
by: Paul Young | last post by:
Hi I am a XML novice so apologies if this is a pretty dumb question. I have thousands of small XML documents which, when checked through XMLSPY, appear to be well formed and valid. However when opened in Internet Explorer some are deemed invalid due the use of an illegal character, the "#" sign. Which of the two packages are correct and why is there a difference? Many thanks Paul Y
28
2944
by: dingbat | last post by:
I'm writing a "tabbed folder" nav bar. Site standards are graphical prettiness, CSS throughout, valid code, but accesibility is ignored where it conflicts with prettiness. The particular issue here is that the graphic designer wants a pretty (non-webbable) font on the shaded nav tabs, so I'm reduced to using bitmaps. To make the 4-way rollovers ("current" and "hover" states) work I'm using the standard "rollerblind" technique with a...
0
5803
by: MB | last post by:
Hi, I am using a web service to call an asp page on a remote server via System.Net.WebClient . The asp page returns a xml stream persisted from a recordset. I am having problems converting the stream into a valid xmltextreader document. I have also converted the document to the simple format without the DTD ( just plain xml file ) and I still get the same error: Illegal characters in path.
1
1793
by: Jonathan Eagle | last post by:
Why is it that when I put char ¿ (ASCII 0169) into a value of attribute in XML, IE gives me this: The XML page cannot be displayed Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later. An invalid character was found in text content. Error processing resource 'file:///C:/...
2
1420
by: Michael Lopez | last post by:
I've written a small web service in c# that takes in a plaintext string, encrypts it, then returns the encrypted string. Some of the characters returned by encryption are illegal xml characters and causes an error when trying to consume the service coldfusion(axis). The service works fine when accessed on its own. I've read that a CDATA block would be the answer, but I have been looking and can't find much information on this. Thanks for...
14
42413
by: deko | last post by:
Is there a way to check user input for illegal characters? For example, a user enters something into a text box and clicks OK. At that point I'd like to run code such as this: illegal = Array(\, /, :, *, ?, ", <, >, |) If Me.TextBox Contains illegal Then MsgBox "You entered illegal characters. Please try again." Me.TextBox = Null
4
8402
by: skinnybloke | last post by:
Hi - I am having problems witrh the code below (obviously) coming up with illegal character for various characters within the field name which is: S_Gift Finder1_0 I have tried various ways of escaping the characters but to no avail. I am unable to change the name of the field as it it comes from an
3
3026
by: =?Utf-8?B?SG9seXNtb2tl?= | last post by:
Hi there, I am having a problem im my webservices method when trying to save a file with latin characters to disk passed through WSE. I have noticed that when trying to read the file name from all the latin characters are converted ? character which is a illegal character for file name. If my file name is N° documento per Romà
2
17815
by: Kamaria | last post by:
I wrote this program to calculate the income tax of a user depending on whether or not they were married: import javax.swing.JOptionPane; public class Income_Tax { public static void main (String args) {
0
8672
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9156
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...
0
9021
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8892
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
6518
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
5860
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
4361
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
4614
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
1998
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.