Search code examples
c#.netxmlreader

XMLReader to read a text


<xhtml:li>
  content1content1content1content1content1content1content1content1
  <xhtml:a href="234455" doc.type="mt">titlex</xhtml:a> 
  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  <xhtml:a href="23452345#23556::ah_234555" doc.type="xx">ZZZZZZZZZZZZZZZZ</xhtml:a> 
  </xhtml:li>

Hi,

From the above xml how to extract the text "xxx...". I am able to take content1... and also process other tags but how to get xxxx ?


Solution

  • It will be of type XmlNodeType.Text. Not knowing your code if you were simply looping through the XmlReader you should get the following node types (ignoring XmlNodeType.Whitespace). You should get the following nodes

    • Element ()
    • Text (content1content..)
    • Element ()
    • Text (titlex)
    • EndElement ()
    • Text (XXXXX....)
    • Element ()
    • Text (ZZZZ...)
    • EndElement ()
    • EndElemnt (/xhtml:li>)

    When the NodeType of your reader is of type text you can use the Value property to retrieve the text.