ReadElementContentAs() throws XmlException

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • cody

    ReadElementContentAs() throws XmlException

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

    XmlReaderSettin gs s = new XmlReaderSettin gs();
    s.IgnoreComment s = true;
    s.IgnoreWhitesp ace = true;
    s.IgnoreProcess ingInstructions = true;

    using (XmlReader reader = XmlReader.Creat e("class.xml" , s))
    {
    reader.Read();
    reader.ReadElem entContentAsStr ing();
    }

    the xml is:

    ...
    <conditiontes t </condition>
    ...

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

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

    I do not understand this, in <conditionthe re is definitely no sub-element.
  • Joe Fawcett

    #2
    Re: ReadElementCont entAs() 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.LocalNam e?

    --

    Joe Fawcett (MVP - XML)


    "cody" <deutronium@gmx .dewrote in message
    news:uXKfeUP7IH A.1192@TK2MSFTN GP05.phx.gbl...
    my code is the following:
    the Read() method positions the cursor on the <conditiontag (verified
    with debugger).
    >
    XmlReaderSettin gs s = new XmlReaderSettin gs();
    s.IgnoreComment s = true;
    s.IgnoreWhitesp ace = true;
    s.IgnoreProcess ingInstructions = true;
    >
    using (XmlReader reader = XmlReader.Creat e("class.xml" , s))
    {
    reader.Read();
    reader.ReadElem entContentAsStr ing();
    }
    >
    the xml is:
    >
    ..
    <conditiontes t </condition>
    ..
    >
    Then an Exception is thrown which reads (translated from german):
    >
    The 'ReadElementCon tentAs()' method is not allowed to be called on
    elements with sub-elements. line 7, position 12.
    >
    I do not understand this, in <conditionthe re is definitely no
    sub-element.

    Comment

    Working...