473,378 Members | 1,390 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,378 software developers and data experts.

XMLTextReader.Read()

Hello,

I get an error
#', hexadecimal value 0x07, is an invalid character. Line 2, position 6358.
on the XMLTextReader.Read() call on a particular node of my XML document.

I need this data to be parsed. This is a cyrillic character data and my comp has a latin code page 1252. Is XML parsing dependant on these values? If yes, is there any means by which I can parse the unicode characters getting into my system?

Any help is appriciated.

Thanks and warm regards,
- Midhun George
Mar 2 '07 #1
5 13945
vijaydiwakar
579 512MB
Hello,

I get an error
#', hexadecimal value 0x07, is an invalid character. Line 2, position 6358.
on the XMLTextReader.Read() call on a particular node of my XML document.

I need this data to be parsed. This is a cyrillic character data and my comp has a latin code page 1252. Is XML parsing dependant on these values? If yes, is there any means by which I can parse the unicode characters getting into my system?

Any help is appriciated.

Thanks and warm regards,
- Midhun George
this error occures when thy xml contains any unwanted char in the filed name tag check it
Mar 3 '07 #2
this error occures when thy xml contains any unwanted char in the filed name tag check it
Hello Vijay,

I know that. the #x07 character cannot be parsed by the XMLText reader. I want to know the reason. I want to if there is any possibility to parse this. If we are not able to parse this, then I want to know about the characters that are not parsed.

This is because, my application cannot guarentee the characters coming in to be parsed as the data is sent to my application by another unicode application. There can be Chinese, Japanese, and all sorts of other characters coming in.The application which runs on a system with codepage 1252. I need to know whether it is possible to configure the system to accept all characters even if they are junk rather than throwing any error (i did not mean exception handling).

Thanks...
Mar 6 '07 #3
kenobewan
4,871 Expert 4TB
I believe that the problem is the ASCII "bell" byte code (#), and that when # is in the code XMLTextReader is expecting an ASCII char. Have you tried replacing it with its ASCII equivalent - & # 3 5 ;?

Here is a list of potential problems that I have found:
Hex Value Explanation
0x01 Start of Heading
0x02 Start of Text
0x03 End of Text
0x04 End of Transmission
0x05 Enquiry
0x06 Acknowledge
0x07 Bell
0x08 Backspace
0x0B Vertical Tabulation
0x0C Form Feed
0x0E Shift Out
0x0F Shift In
0x10 Data Link Escape
0x11 Device Control One
0x12 Device Control Two
0x13 Device Control Three
0x14 Device Control Four
0x15 Negative Acknowledge
0x16 Synchronous Idle
0x17 End of Transmission Block
0x18 Cancel
0x19 End of Medium
Mar 7 '07 #4
Thanks a lot. Now I get the actual problem.

XMLTextReader.Read() Throws an exception when an unwanted character like the ones mentioned above comes in the stream. How can I ignore this?

This is the pseudo code
Expand|Select|Wrap|Line Numbers
  1. try
  2. {
    reader = new XmlTextReader(filename);
    reader.WhitespaceHandling = WhitespaceHandling.None;
    while (true) 
    {
    try
    {
    if (!reader.Read())
    break;
    // Some processing
    }
    catch (XMLException XML_exc)
    {
    //*** NEED TO DO SOMETHING TO SKIP THIS NODE ***
    //*** ELSE THIS IS AN INFINITE LOOP
    continue;
    }
    }
    }
  3. catch (Exception e) //other exceptions
  4. {
    //some processing
    }
  5. finally
  6. {
    if (reader != null)
    reader.Close()
    }
Mar 14 '07 #5
beanwa
1
Here's a handy string cleansing class to get rid of the invalid characters before sending them to your xml file. I got a little creative naming the Hashtable.

Expand|Select|Wrap|Line Numbers
  1. string cleanString = BytesSite.StringHelp.ValidString(possibleBadString);
  2.  
  3. -----------------------------------------------------------------------------------------------------------
  4.  
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Collections;
  10.  
  11. namespace BytesSite
  12. {
  13.     internal class StringHelp
  14.     {
  15.         static Hashtable Guitar = new Hashtable();
  16.  
  17.         static string convertAsciiToHex(String pAsciiText) 
  18.         { 
  19.             StringBuilder sBuffer = new StringBuilder();
  20.             for (int i = 0; i < pAsciiText.Length; i++) 
  21.             {
  22.                 sBuffer.Append(Convert.ToInt32(pAsciiText[i]).ToString("x")); 
  23.             } 
  24.             return sBuffer.ToString().ToUpper(); 
  25.         }
  26.  
  27.         static bool invalidHex(string pHexValue)
  28.         {
  29.             populateGuitar();
  30.             return Guitar.ContainsKey(pHexValue);
  31.         }
  32.  
  33.         public static string ValidString(string pString)
  34.         {
  35.             string returnString = string.Empty;
  36.             for (int i = 0; i < pString.Length; i++)
  37.             {
  38.                 if (!invalidHex(convertAsciiToHex(pString[i].ToString())))
  39.                     returnString += pString[i].ToString();
  40.             }
  41.  
  42.             return returnString;
  43.         }
  44.  
  45.         private static void populateGuitar()
  46.         {
  47.             if (Guitar.Count == 0)
  48.             {
  49.                 Guitar.Add("1", "1");
  50.                 Guitar.Add("2", "2");
  51.                 Guitar.Add("3", "3");
  52.                 Guitar.Add("4", "4");
  53.                 Guitar.Add("5", "5");
  54.                 Guitar.Add("6", "6");
  55.                 Guitar.Add("7", "7");
  56.                 Guitar.Add("8", "8");
  57.                 Guitar.Add("10", "10");
  58.                 Guitar.Add("11", "11");
  59.                 Guitar.Add("12", "12");
  60.                 Guitar.Add("13", "13");
  61.                 Guitar.Add("14", "14");
  62.                 Guitar.Add("15", "15");
  63.                 Guitar.Add("16", "16");
  64.                 Guitar.Add("17", "17");
  65.                 Guitar.Add("18", "18");
  66.                 Guitar.Add("19", "19");
  67.                 Guitar.Add("B", "B");
  68.                 Guitar.Add("C", "C");
  69.                 Guitar.Add("E", "E");
  70.                 Guitar.Add("F", "F");
  71.             }
  72.         }
  73.     }
  74. }
  75.  
May 27 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Meir S. | last post by:
I think the following is a bug in XmlTextReader: I need to process large XMLs, that are typically constructed of many small elements nested in the root element. Each inner element represents a...
3
by: keldan | last post by:
I am hoping someone on this list can shed some light on the below issue for me. I am using XmlTextReader to read from an XML file. Unfortunately, an exception is thrown ("Index was outside the...
2
by: Mitch | last post by:
I have some simple HTML I'm trying to read with the XMLTextReader. As in the MSDS examples, I set up a loop to read each XML node: while (reader.Read()) { switch (reader.NodeType) { case...
5
by: Geoff Bennett | last post by:
While parsing an XML document, my TextReader instance skips nodes. For example, in this fragment: <Person Sex="Male" FirstHomeBuyer="No" YearsInCurrentProfession="14"> <RelatedEntityRef...
5
by: Chris | last post by:
Hi, the docs say : "The Xml-document is not loaded into memory when using XmlTextReader, as opposed to using the DOM where the entire document is loaded in memory" but, when using...
1
by: edi | last post by:
Hi, I have MS .Net Framework v1.1.4322. I have this XML file: <?xml version="1.0" ?> <!--here there are two spaces at the beginning--> <aaa> <a id="1"> <Dept>Finance</Dept>
3
by: prasad | last post by:
Hi, I am using XMLTextReader class to read the xml files. In some cases xml declaration tag might start after space/tab charecters. These kind of files are supported by the browsers and xml dom's...
1
by: SHC | last post by:
Hi all, I did the "Build" on the attached code in my VC++ .NET 2003 - Windows XP Pro PC. On the c:\ screen, I got the following: Microsoft Development Environment An unhandled exception of type...
3
by: Kjeld | last post by:
My scenario: I'm using an XmlTextReader to Deserialize serveral classes from a single xml document. Every class i pass the source stream, containing the xml. Each class subsequently creates an...
2
by: Q | last post by:
I am feeding XmlTextReader a URL that returns the XML that then gets parsed. The URL forms a query that affects how much data is returned in XML but not the format of the data. The problem is...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.