ReadElementContentAs() throws XmlException

my code is the following:
the Read() method positions the cursor on the <condition> tag (verified 
with debugger).

XmlReaderSettings s = new XmlReaderSettings();
s.IgnoreComments = true;
s.IgnoreWhitespace = true;
s.IgnoreProcessingInstructions = true;

using (XmlReader reader = XmlReader.Create("class.xml", s))
{
	reader.Read();
	reader.ReadElementContentAsString();
}

the xml is:

...
<condition> test </condition>
...

Then an Exception is thrown which reads (translated from german):

The 'ReadElementContentAs()' method is not allowed to be called on 
elements with sub-elements. line 7, position 12.

I do not understand this, in <condition> there is definitely no sub-element.
0
deutronium (13)
7/23/2008 6:53:44 PM
dotnet.xml 7266 articles. 0 followers. Follow

1 Replies
629 Views

Similar Articles

[PageSpeed] 45

I can't reproduce that with your example code, are you certain that you're 
on the correct element?
Have you output reader.LocalName?

-- 

Joe Fawcett (MVP - XML)
http://joe.fawcett.name

"cody" <deutronium@gmx.de> wrote in message 
news:uXKfeUP7IHA.1192@TK2MSFTNGP05.phx.gbl...
> my code is the following:
> the Read() method positions the cursor on the <condition> tag (verified 
> with debugger).
>
> XmlReaderSettings s = new XmlReaderSettings();
> s.IgnoreComments = true;
> s.IgnoreWhitespace = true;
> s.IgnoreProcessingInstructions = true;
>
> using (XmlReader reader = XmlReader.Create("class.xml", s))
> {
> reader.Read();
> reader.ReadElementContentAsString();
> }
>
> the xml is:
>
> ..
> <condition> test </condition>
> ..
>
> Then an Exception is thrown which reads (translated from german):
>
> The 'ReadElementContentAs()' method is not allowed to be called on 
> elements with sub-elements. line 7, position 12.
>
> I do not understand this, in <condition> there is definitely no 
> sub-element. 

0
7/24/2008 7:29:07 AM
Reply:

Similar Artilces:

CDO throwing Access Denied error in Outlook 2003
Hi, Whenever i access the Messages property of the Contact MAPI Folder, i am getting the following error Collaboration Data Objects Message : [Collaboration Data Objects - [E_ACCESSDENIED(80070005)]] What could be the prob? Thanks Bala I'm not sure what the problem is, your code works fine here but it does throw up the address book access security prompt before access to the contacts folder is allowed. Are you using the Beta 2 refresh? It's possible that access to contacts was more severely restricted in earlier beta versions, although I haven't seen any bugs abo...

Throws error on Outlook shutdown
Hi, I have 3 Add-In installed for Outlook which are developed in C#. When I follow a particular sequence by using these add-ins, I am getting error on Outlook shutdown. Please refer the following log errors, 005-10-13T08:29:45.858Z INFO GOSH CExecutor.DispatchEvent result is ABORT 2005-10-13T08:29:57.123Z INFO GOSH CExecutor.DispatchEvent result is FALSE 2005-10-13T08:29:57.139Z TRACE GOSH Shutdown GOSH framework OK 2005-10-13T08:29:57.733Z ERROR GOSH Unhandled exception: System.NullReferenceException: Object reference not set to an instance of an object. at System.Drawing.SafeNativeMeth...

How to throw an exception
Hi all, I have an function like this A & foo(int a, int b) {... if (a<b) { //throw an exception } } where A is a class. Inside this function , I need to check if a<b, if yes then throw an exception, how should I do , then? I didn't do this before, any help will be appreciated! Best wishes, Green On 29 Nov 2006 01:39:49 -0800, "flamesky" <myflamesky@hotmail.com> wrote: >Hi all, > >I have an function like this > >A & foo(int a, int b) >{... > if (a<b) > { //throw an exception > } >} > >where A is a class...

HELP! Why I can now throw success the exception in VC++?
Hi, I am using the following codes to connect to my web page, it works fine ... but even I detect the exception, some time my application shows:"The Web server connection was rest" then my application can not connect any more! =================================================== do { f_error = false; try { pConnect = pInetSession->GetFtpConnection (strServerName, user, password, nPort, FALSE); } catch (CInternetException* pEx) { pEx->Delete(); pConnect = NULL; f_error = true; } if(f_error) { ...

Throwing an Exception
Hi, I have a little piece of code that I do not know why the "an unhandled exception has occured" msg box pops up. //....within an initialization function try { device->Write("IFC\n"); } catch (char *str) { //....write the type of error in the status bar return; } The Write function will throw an exception when the GPIB device responded with an error msg or timed out. void GPIBDevice::Write(char* command) throw(...) { //.......stuff.... if (ibsta & ERR) { printf ("iberr = %d", iberr); throw getErrorMsg(); } //if } //Write Everyti...

SBS2k3: website under companyweb throwing 404 not found
The default 2k3 companyweb website functions correctly. We want to create a virtual directory under http://companyweb/our_domain_name. The directory is located under C:\Inetpub\Intranet\our_domain_name. The directory is set for internet sharing under Companyweb.On IIS it is listed under Companyweb with Application Name 4\our_domain_name and starting point <companyweb>\our_domain_name. Directory browsing is allowed and under documents the default content page is added and placed first. It is plain html and the site has no ASP or other scripts. All very basic. Still it...

ReadElementContentAs() throws XmlException
my code is the following: the Read() method positions the cursor on the <condition> tag (verified with debugger). XmlReaderSettings s = new XmlReaderSettings(); s.IgnoreComments = true; s.IgnoreWhitespace = true; s.IgnoreProcessingInstructions = true; using (XmlReader reader = XmlReader.Create("class.xml", s)) { reader.Read(); reader.ReadElementContentAsString(); } the xml is: ... <condition> test </condition> ... Then an Exception is thrown which reads (translated from german): The 'ReadElementContentAs()' method is not allowed to be called on ele...

Update on client side throws exception
Hi all, I'm updating a SQL Server 2008 database table using SqlDataAdapter/DataSets and Visual Studio C# on the client side. TARGET TABLE TO UPDATE: T_Order FIELDS: TAXOR [nvarchar] (255) NULL, TAXPARTSIZE [nvarchar] (255) NULL TAXSBO [nvarchar] (255) NULL TAXGRP [nvarchar] (255) NULL TAXSBGRP [nvarchar] (255) NULL SOURCE TABLE: ConusSolLyr FIELDS: TAXOR [nvarchar] (255) NULL, TAXPARTSIZE [nvarchar] (255) NULL TAXSBO [nvarchar] (255) NULL TAXGRP [nvarchar] (255)...

CString.ReverseFind() and throw
in the help of CString.ReverseFind(), it says int ReverseFind( XCHAR ch ) const throw(); what is this throw? if it is throwing an exception, how to catch it? thanks. WJ On Mon, 9 Jul 2007 14:48:02 -0700, WJ <WJ@discussions.microsoft.com> wrote: >in the help of CString.ReverseFind(), it says > >int ReverseFind( > XCHAR ch >) const throw(); > >what is this throw? if it is throwing an exception, how to catch it? thanks. > >WJ See: Exception Specifications http://msdn2.microsoft.com/en-us/library/wfa0edys(VS.80).aspx -- Doug Harrison Visual C++ MVP...

Should unimplmented pure function throw a compile error?
It's been a while since I have written anything with abstract classes. If I derive a class from my abstract class and do not implement a pure virtual function of the base class in the derived class, shouldn't the compiler throw an error? -- Bruce E. Stemplewski GarXface OCX and C++ Class Library for the Garmin GPS www.stempsoft.com yes, if you try to instantiate the class in your code it should. "Bruce E. Stemplewski " <BruceStemplewski@hotmail.com> wrote in message news:uaGJZhYCFHA.3732@TK2MSFTNGP14.phx.gbl... > It's been a while since I have written anyt...

Formula throwing up an error
Can anyone tell me why I should be getting an error. Range("L10:L7800").FormulaArray = "=IF(SUM(--('A Use'!A$1:A$10000&'A Use'!C$1:C$10000=B10&"G house")),"G house","")" B10 by the way is a relative reference. Thank you for your time. Look at where your double quotes are located; each set surrounds something that Excel will treat as a single string. Also, you will need a "&" between each string or variable. "=IF(SUM(--('A Use'!A$1:A$10000&'A Use'!C$1:C$10000=B1...

AfxOleInit throws an exception
Hi, I am doing a project for Unicode complaiance. The project setting are changed to _UNICODE. The application works fine in Debug mode. But when the configuration is changed to Release 'AfxOleInit' throws an exception. Any idea why this could happen ? Regards, ND Catch the exception and see what it says. try { AfxOleInit(); } catch (CException *pExp) { char Buffer[255]; pExp->GetErrorMessage(Buffer,255,NULL); MessageBox(Buffer); } AliR. "ND" <ND@discussions.microsoft.com> wrote in message news:615E05E3-CC6F-4A40-B18B-0D4233AC32CC@microsoft....

Throwing two dice and print out the total of each throw
in the days of line numbers i build a short programme to simulate the throwing of two dice with a screen print out the number of times, a particular number randomly came up . My question is can this run using Access VB ? Any constructive advise would be most welcome . The old code is as follows: REM THROWING 2 DICE CLS INPUT "How many Throws", N Dim A(12) FOR M = 1 TO 12 A(M) = 0 Next M FOR T = 1 TO N X = int(6 * rnd (1)) + 1 Y = int(6 * rnd (1)) + 1 Z = X + Y A (Z) = A(Z)+1 NEXT T CLS PRINT TAB(5); "Total" ; TAB(25); " Frequency" PRINT...

Sum (throw out highest and lowest)
I am working on a contest scoring sheet for the California State Old Time fiddlers Association and it is contest policy to throw out the highest score and the lowest score and add the remaining middle (3) judges scores. (There are generally 5 judges - don't think there would ever be more than that.) The total of the middle three is used for future ranking points added to future scores, so "average" won't work in this application. Right now we are working this out manually - sure woudl be sweet to be able to have a formula that works it out for us. Thanks for any help. ...

Addnew throwing error 3027
In one sub I am trying to add a record to to "Abstracts" table. Records in the abstracts table are related to the States and counties tables. So I open a recordset with joins. I have tried several times after checking everything out and cannot find any reason why the recordset should be read only. I have also checked for a lock file (as suggested in another post). The code: Private Sub cmdSave_Click() Dim strSQL As String Dim rs As DAO.Recordset Dim db As DAO.Database If blnCheckFields Then 'save new abstract Set db = CurrentDb() ...

If my System.IO.StreamWriter Write method throws "The specified network name is no longer available." and I try to Dispose or Close it in the finaly clause the close or dispose method just throws "The
If my System.IO.StreamWriter Write method throws "The specified network name is no longer available." and I try to Dispose or Close it in the finaly clause the close or dispose method just throws "The specified network name is no longer available." again. how to clean this up? after this the stream writer is stuck connected until i restart my process. ...

throwing CException
I have extended CException into CMyException. I'm throwing it like this: if (error) throw new CMyException("Message", TRUE); How should I catch it? Is this OK: try { callSomeFunc(); } catch (CException &e) { char msg[999]; e.GetErrorMessage(msg, sizeof(msg)); AfxMessageBox(msg); return; } or I _have_ to use "CException *e"? Also, do I have to call e->Delete() and when? Is this OK: > try { > callSomeFunc(); > } catch (CException &e) { > char msg[999]; > e.GetErrorMessage(msg, sizeof(msg)); > AfxMessageBox(msg); > ...

CFile::GetStatus throws an exception when run from CD
I have a small app that is checking to see if the file dotnetfx.exe is present in the same directory as my executable. I am running VS.NET 2003 and using unmanaged C++. Everything works great, as long as my executable is not on a CD. When burned to CD, the call to GetStatus will throw "the parameter is incorrect". The strings are correct (and obviously it runs fine when not burnt to CD). CString strHelpFilePath = AfxGetApp()->m_pszHelpFilePath; int iFileLoc = strHelpFilePath.ReverseFind(_T('\\')); CString strFxLoc = strHelpFilePath.Left(iFileLoc + 1) + ...

this web site throwing blank pages
anyone else noting that this web site is throwing alot of unreachable web pages suddenly? Right now all my received email notifications of a reply ...the link on that email does not work to the reply.... Also alot of times during the sign-in it goes to nowhere.... -- NTC Yes, the sign-in always breaks/fails half way in and you need to reload to complete the process if using the Web interface. -- Daniel Pineault "NetworkTrade" wrote: > anyone else noting that this web site is throwing alot of unreachable web > pages suddenly? > > Right now all my receive...

Throwing a exception in the constuctor?
I thought I learned a long, long time ago that you should not throw an exception in a constructor? Am I rembering this fact correctly or did I get incorrect information so long ago. Or maybe my memory is just fuzzy? ;) ...

SignedXML throws error
When I try to used the CheckSignature Method of SignedXML I get the following error. "Unknown transform has been encountered. at System.Security.Cryptography.Xml.Reference.LoadXml(XmlElement value)\r\n at System.Security.Cryptography.Xml.SignedInfo.LoadXml(XmlElement value)\r\n at System.Security.Cryptography.Xml.Signature.LoadXml(XmlElement value)\r\n at System.Security.Cryptography.Xml.SignedXml.LoadXml(XmlElement value)\r\n at SAML.Form1.button2_Click(Object sender, EventArgs e) in d:\\omtest\\saml\\form1.cs:line 295" string Any ideas what might be going wrong,...

Throw Exception from a dll
Hi, I have got a problem then throwing exception from a dll and catch it in the exe. It is work to catch the object but then it leave the catch area and the object it being destroyed the program crach. What I have understood is that a dll and exe have different heaps and that is the problem. Can someone help me? How can a throw exception from a dll to the exe? /Mats Most likely you are using static linking in one or both of the components. Do not use static linking. Then you will have one heap. joe On Wed, 5 Nov 2003 00:47:55 -0800, <gnms71@hotmail.com> wrote: >Hi, I h...

Bookmark Macro throwing errors
HNY all, This macro used to Work in 2003 but now does not work in either 03 or 07 (if you have 2010 please feel free to test it in there too). I have marked rows so far throwing errors with '*****. I am sure more rows will throw errors. Option Explicit Const varName As String = "BookmarkCounter" Const varDuplicateName As String _ = "DuplicateBookmarkCounter" Sub CreateBookmark() ' TEST ' 'Variable declaration Dim rng As Word.Range Dim BookmarkName As String Dim var As Word.Variable Dim varName As String '**** Added this lin...

Exchange 2003 cannot access system Manager (throws MAPI32.dll Q266418 error Popup)
Thank You for reading my post. We have SBS2003 with Exchange Server. For some time now, whenever I attempt to use the Exchagne System Manager, it fails to load, throwing an error dialog box which reads... Exchange System Manager. Exchange detected that "c:\windows\system32=MAPI32.DLL" is not the correct versin required to run Exchange System Manger or Exchange Server 2003. This may cause failures in Exchange System Manager, affect availability of your server, or both. For more information see Microsoft Knowledge Base article Q266418 at http://support/microsoft.com The...

CFile does not throw exception.
Experts, I am using CFile class to do file reading and writing operation. I use the following codes to catch a CFileException when open up a file: CFile fScr; CFileException fEx; if(!fSrc.Open(_T("c:\\1.txt"),CFile::modeRead,&m_fEx)) { fEx.ReportError(); // Then write code to abort operation } This code will catch the file access violation exception, meaning that when the target file is already opened, then CFile::Open(,,,) will return FALSE and the code will report error. But, when there is no "c:\1.txt" file exists, the apllication will have a run time err...