473,662 Members | 2,752 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1677
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 interoperabilit y in .NET classes by enforcing
standards compliance (since interoperabilit y 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.pennywises olutions.com> wrote in message
news:%2******** ********@tk2msf tngp13.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******** ************@co mcast.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 interoperabilit y in .NET classes by enforcing
standards compliance (since interoperabilit y 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.pennywises olutions.com> wrote in message
news:%2******** ********@tk2msf tngp13.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(n ew WhiteSpaceTrimm ingStream(new FileStream(file name)));

Where

class WhiteSpaceTrimm ingReader : TextReader {
StreamReader file;
bool firstRead = true;

WhiteSpaceTrimm ingStream(Strea mReader file) {
this.file = file;
}

public override int Read(char[] buffer, int offset, int len) {
int found = 0;
while (found == 0) {
found = file.Read(buffe r, 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(buff er, i, buffer, 0, found - i);
found -= i;
}
}
}
return found;
}

// and delegate the rest of Stream API to underlying stream.
}
"prasad" <pr************ @net.pennywises olutions.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.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******** ************@co mcast.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 interoperabilit y in .NET classes by enforcing
standards compliance (since interoperabilit y 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.pennywises olutions.com> wrote in message
news:%2******** ********@tk2msf tngp13.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
1204
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 System.Xml.Schema Module Module1
3
4192
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 manipulation on #text nodes of only certain named elements. example while (xmltextreader.Read()) { if (xmltextreader.NodeType == XmlNodeType.Text)
2
2634
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 is the program itself : ******************************************************************** using System; using System.Xml; using System.Xml.Schema;
3
1591
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. System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: The specified value must be greater than 0. at System.Net.ServicePoint.set_ConnectionLimit(Int32 value) at System.Xml.XmlDownloadManager.GetNonFileStream(Uri...
4
1365
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 XMLVALIDATINGREADER? I am getting an invalid cast. It seems that although the XSLTRANSFORM 'transform' method does return a XMLREADER object and you can work with that, you can not pass it
1
2513
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 (which works fine), to send data, but on the same stream be able to read data (which is causing problems). In the function "bool Connect()", we want to instantiate the XmlTextReader with the stream that we got from the 'TcpClient client', but...
1
1234
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 "C:\WINDOWS\system32\content\site_text.xml".' I am loading my XMLTextreader in the following way:
4
1688
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 have a very simple XML file that I wish to parse using Xmltextreader, but I seem to be having a lot of poblems with it. I have a subroutine that I pass a string into, and what I need to do is to find the element where that string exists, and then...
0
1102
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 back (in xml) The searches are just URLs with querystrings. Each request sets a boolean to true when it has got a reply from the search engine. I have declare the booleans as 'volatile'.
0
8345
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
8857
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
8768
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...
0
8633
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7368
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6186
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
4348
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1999
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1754
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.