Connecting Tech Pros Worldwide Forums | Help | Site Map

ReadElementContentAs() throws XmlException

cody
Guest
 
Posts: n/a
#1: Jul 23 '08
my code is the following:
the Read() method positions the cursor on the <conditiontag (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:

...
<conditiontest </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 <conditionthere is definitely no sub-element.

Joe Fawcett
Guest
 
Posts: n/a
#2: Jul 24 '08

re: ReadElementContentAs() throws XmlException


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.dewrote in message
news:uXKfeUP7IHA.1192@TK2MSFTNGP05.phx.gbl...
Quote:
my code is the following:
the Read() method positions the cursor on the <conditiontag (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:
>
..
<conditiontest </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 <conditionthere is definitely no
sub-element.
Closed Thread