473,399 Members | 2,478 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,399 software developers and data experts.

Problem with XMLTextReader

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
but the xmltextreader's are not supporting to read this kind of files.

Using XMLTextReaders is there anyway to read this kind of files.

Thanks in advance,
Prasad Dannani.

Nov 12 '05 #1
3 1663
Yes, it turns out that spaces before the xml declaration is not fully
standards compliant, so you XML would not have worked across other platforms
and we opted to go for best interoperability in .NET classes by enforcing
standards compliance (since interoperability is what XML is all about).

You could preload the file into a string and Trim the spaces then pass the
result via StringReader to XmlReader or you could provide a more efficient
solution by wrapping FileStream with your own clever Stream class that
strips initial whitespace.

"prasad" <pr************@net.pennywisesolutions.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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
but the xmltextreader's are not supporting to read this kind of files.

Using XMLTextReaders is there anyway to read this kind of files.

Thanks in advance,
Prasad Dannani.

Nov 12 '05 #2
In mycase, i have to use XMLTextReader because of its advantages. But if i
use filestreams and load the complete info to a string and then using
xmlreader classes to read the values then its a double work with out any
advantage.

Anyway thanks for helping. can anyone please suggest me that is there any
property or class to help me which will support all the advantages of
xmltextreaders
"Chris Lovett" <so*****@nospam.please> wrote in message
news:yp********************@comcast.com...
Yes, it turns out that spaces before the xml declaration is not fully
standards compliant, so you XML would not have worked across other platforms and we opted to go for best interoperability in .NET classes by enforcing
standards compliance (since interoperability is what XML is all about).

You could preload the file into a string and Trim the spaces then pass the
result via StringReader to XmlReader or you could provide a more efficient
solution by wrapping FileStream with your own clever Stream class that
strips initial whitespace.

"prasad" <pr************@net.pennywisesolutions.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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
but the xmltextreader's are not supporting to read this kind of files.

Using XMLTextReaders is there anyway to read this kind of files.

Thanks in advance,
Prasad Dannani.


Nov 12 '05 #3
There is no way to tell XmlTextReader to ignore the whitespace.

My suggestion of passing a wrapper Stream to XmlTextReader does require
double copy of read buffers, but other than it is pretty efficient.

new XmlTextReader(new WhiteSpaceTrimmingStream(new FileStream(filename)));

Where

class WhiteSpaceTrimmingReader : TextReader {
StreamReader file;
bool firstRead = true;

WhiteSpaceTrimmingStream(StreamReader file) {
this.file = file;
}

public override int Read(char[] buffer, int offset, int len) {
int found = 0;
while (found == 0) {
found = file.Read(buffer, offset, len);
if (firstRead) {
int i = 0;
while (i < found) {
char ch = buffer[i];
if (ch != ' ' && ch != '\t' && ch != '\r' && ch != '\n')
{
break;
}
}
if (i > 0) {
Array.Copy(buffer, i, buffer, 0, found - i);
found -= i;
}
}
}
return found;
}

// and delegate the rest of Stream API to underlying stream.
}
"prasad" <pr************@net.pennywisesolutions.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
In mycase, i have to use XMLTextReader because of its advantages. But if i
use filestreams and load the complete info to a string and then using
xmlreader classes to read the values then its a double work with out any
advantage.

Anyway thanks for helping. can anyone please suggest me that is there any
property or class to help me which will support all the advantages of
xmltextreaders
"Chris Lovett" <so*****@nospam.please> wrote in message
news:yp********************@comcast.com...
Yes, it turns out that spaces before the xml declaration is not fully
standards compliant, so you XML would not have worked across other

platforms
and we opted to go for best interoperability in .NET classes by enforcing
standards compliance (since interoperability is what XML is all about).

You could preload the file into a string and Trim the spaces then pass
the
result via StringReader to XmlReader or you could provide a more
efficient
solution by wrapping FileStream with your own clever Stream class that
strips initial whitespace.

"prasad" <pr************@net.pennywisesolutions.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
> 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
> but the xmltextreader's are not supporting to read this kind of files.
>
> Using XMLTextReaders is there anyway to read this kind of files.
>
> Thanks in advance,
> Prasad Dannani.
>
>
>



Nov 12 '05 #4

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

Similar topics

3
by: Fede | last post by:
Hi to all, I've written a simple XML file and I'm trying to validate it using XMLValidatingReader and ValidationEventHandler event. This is my code: Imports System.Xml Imports...
3
by: Pete | last post by:
I'm trying to read an XML document and write out a slightly modified version using the XmlTextWriter. I'm basically trying to copy all the nodes exactly as they are read and do some text...
2
by: Joris Janssens | last post by:
I'm trying to write a program for validating XHTML 1.1-documents against the XHTML 1.1 DTD (which is actually the same as validating an XML-file) but I always get a "(404) Not found" error. This...
3
by: Keith | last post by:
Anyone else experience this problem when using the XmlTextReader? (See stack trace below) I've installed the patch from knowledge base article 839588, but it didn't fix it. ...
4
by: badbetty | last post by:
Hello and thank you for reading on (hopefully). How does one typecast the XMLREADER returned from the XSLTRANSFORM method 'transform' into XMLTEXTREADER, so it can be passed in to an...
1
by: Borgbjerg | last post by:
I've got a multi-threaded server (we are very early in the project, trying to uncover some risks), and I want to send data using XML. The class ServerAdapter is supposed to connect to the server...
1
by: Calvin X | last post by:
Hi All, I am getting the following error when I try to open an xml file that is in a directory just underneath the site root. 'Could not find a part of the path...
4
by: Paul Bromley | last post by:
I thought that XMLTextReader would be simple to use, but I have run into problems with it! I seem to have great difficulty extrcting the text of specific elements from a very simple XML file. I...
0
by: davidpenty | last post by:
Hi there, I am having some problems with a multi-threaded asp.net seach page. My search page sends off four asynchronous http requests to four search engines then waits for the results to come...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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:
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.