Is it possible to use the using statement with XmlTextReader?
I tryed to use it, but it gives me the error message:
Cannot implicitly convert type 'System.Xml.Xml TextReader' to
'System.IDispos able'
Is there something I am doing wrong?
// This no worky
using(XmlTextRe ader xtr = new XmlTextReader(" C:\\myfile.xml" ))
{
// Do something
} 3 9647
No. You're not doing anything wrong.
You can only use the using statement with classes that implement the
IDisposable interface. The XmlTextWriter doesn't implement that interface,
hence the error message.
The work around is to do what the C# complier does for using statement:
XmlTextWriter writer = ...
try
{
// do wtuff with the writer
}
finally
{
writer.Close();
}
--
HTH
Christoph Schittko [MVP]
Software Architect, .NET Mentor
"Russell Mangel" <ru*****@tymer. net> wrote in message
news:OJ******** ******@TK2MSFTN GP10.phx.gbl... Is it possible to use the using statement with XmlTextReader? I tryed to use it, but it gives me the error message: Cannot implicitly convert type 'System.Xml.Xml TextReader' to 'System.IDispos able'
Is there something I am doing wrong?
// This no worky using(XmlTextRe ader xtr = new XmlTextReader(" C:\\myfile.xml" )) { // Do something }
Aww, bummer, I figured that this was the case, but I wanted to ask someone.
I like the using statement.
Thanks for the reply
Russ
"Christoph Schittko [MVP]" <ch************ ********@austin .rr.com> wrote in
message news:#X******** ******@tk2msftn gp13.phx.gbl... No. You're not doing anything wrong.
You can only use the using statement with classes that implement the IDisposable interface. The XmlTextWriter doesn't implement that interface, hence the error message.
The work around is to do what the C# complier does for using statement:
XmlTextWriter writer = ... try { // do wtuff with the writer } finally { writer.Close(); }
-- HTH Christoph Schittko [MVP] Software Architect, .NET Mentor
"Russell Mangel" <ru*****@tymer. net> wrote in message news:OJ******** ******@TK2MSFTN GP10.phx.gbl... Is it possible to use the using statement with XmlTextReader? I tryed to use it, but it gives me the error message: Cannot implicitly convert type 'System.Xml.Xml TextReader' to 'System.IDispos able'
Is there something I am doing wrong?
// This no worky using(XmlTextRe ader xtr = new XmlTextReader(" C:\\myfile.xml" )) { // Do something }
You can write your own class
DisposableXmlTe xtWriter : XmlTextWriter, IDisposable
{
}
to add IDisposable semantics to the XmlTextWriter
--
HTH
Christoph Schittko [MVP]
Software Architect, .NET Mentor
"Russell Mangel" <ru*****@tymer. net> wrote in message
news:ue******** *****@tk2msftng p13.phx.gbl... Aww, bummer, I figured that this was the case, but I wanted to ask
someone. I like the using statement.
Thanks for the reply Russ
"Christoph Schittko [MVP]" <ch************ ********@austin .rr.com> wrote in message news:#X******** ******@tk2msftn gp13.phx.gbl... No. You're not doing anything wrong.
You can only use the using statement with classes that implement the IDisposable interface. The XmlTextWriter doesn't implement that
interface, hence the error message.
The work around is to do what the C# complier does for using statement:
XmlTextWriter writer = ... try { // do wtuff with the writer } finally { writer.Close(); }
-- HTH Christoph Schittko [MVP] Software Architect, .NET Mentor
"Russell Mangel" <ru*****@tymer. net> wrote in message news:OJ******** ******@TK2MSFTN GP10.phx.gbl... Is it possible to use the using statement with XmlTextReader? I tryed to use it, but it gives me the error message: Cannot implicitly convert type 'System.Xml.Xml TextReader' to 'System.IDispos able'
Is there something I am doing wrong?
// This no worky using(XmlTextRe ader xtr = new XmlTextReader(" C:\\myfile.xml" )) { // Do something }
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Daniel |
last post by:
Hello =)
I have an object which contains a method that should execute every x ms. I
can use setInterval inside the object construct like this -
self.setInterval('ObjectName.methodName()', this.pinginterval);
- but is there no way to do this without using the literal ObjectName? If I
write 'this.methodName()' I get "Line 1 Char 1: Object doesn't support this
property or method." in IE, and nothing happens in Firebird.
|
by: Japhy |
last post by:
Hello,
I'm am pulling data from a mysql db and want to use the data to
populate a <ul.
Here are relavent parts of my code :
$wohdate = mysql_result($wohRS,$wohndx,woh_date);
$woh_display .="<li>".$wohdate."</li>" ;
$TemplateText = Replace($TemplateText,"@$wohdisplayndx@",$woh_display);
|
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 command, so I have to parse and
execute them according to the order they appear in the ROOT element.
I don't want to use XmlDocument for the entire huge XML,
but can use XmlDocument for each small element at the time.
|
by: Andy Neilson |
last post by:
I've run across a strange behaviour with XmlSerializer that I'm unable to explain. I came across this while trying to use XmlSerializer to deserialize from a the details of a SoapException. This should have worked fine since the class in question was already being serialized and deserialized as part of a Web service interface. What I found was that by deserializing from an XmlNodeReader instead of an XmlTextReader, XML Serialization doesn't work...
|
by: Emsi |
last post by:
Hello,
how can I read values of child nodes with the XmlTextReader?
File format:
<root>
<items>
<item>
<field1>value1</field1>
<field2>value2</field2>
| |
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
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.
|
by: Dica |
last post by:
hi all
first off, i'm not trying to cross post, but couldn't find this newsgroup
earlier (got here from a recommendation on microsoft.public.vb, where i
originally posted this question).
anyhow, i'm just getting into .Net and am trying to parse a document, but
not able to read the values for the nodes consistently. anybody know what
i'm doing wrong? it seems that i'm able to console.writeLine the value of
the node at the beginning of...
|
by: Jimmy |
last post by:
Hello,
If I want to check in C# code that if there is a & in my string variable
using
RegExp, how should I inform RegExp about &-char? Is just &, \&, & or
something else? I have strucled with this small issue two days and I still
not
sure how C# accpets &-char in Regular Expresions.
Can anyone help?
|
by: apiringmvp |
last post by:
All,
So I am creating a function that gets a short blurb of html from a
blog. I would like to retain all html formating and images. The code
below works well, with the exception of one issue.
My issue:
---------------------
When a blog's html has attributes with no quotes i get an exception.
|
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...
|
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,...
| |
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...
|
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,...
|
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...
|
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...
|
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...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |