Untested, but this should give you what you want (2 changes to your code):

 string strStreet="";
 FileStream fs = new
 FileStream(myXml.xml",FileMode.Open);
 XmlTextReader myReader = new XmlTextReader(fs);
 while(myReader.Read())
 {
   if(myReader.NodeType == XmlNodeType.Element)
   {
     switch(myReader.Name)
     {
       case "street":
          strStreet = myReader.Value;
     }
   }
 }


Richard

> -----Original Message-----
> From: The DOTNET list will be retired 7/1/02
> [mailto:[EMAIL PROTECTED]]On Behalf Of Nischal Muthana
> Sent: 21 June 2002 00:34
> To: [EMAIL PROTECTED]
> Subject: [DOTNET] XmlTextReader with an XPath
>
>
> Hi All
>
> I have a small program which uses XmlTextReader to
> read through an XML file and get the appropriate
> values from the file.
>
> Following is my XML file.
> <?xml version="1.0" encoding="UTF-8"?>
> <customer>
>         <name>Nischal</name>
>         <address>
>                 <currAddress>
>                   <street></street>
>                   <city></city>
>                   <state></state>
>                 </currAddress>
>                 <prevAddress>
>                   <street></street>
>                   <city></city>
>                   <state></state>
>                 </prevAddress>
>         </address>
> </customer>
>
> I believe with XmlTextReader I cannot specify a
> particular node name and get the Text of that node. I
> am tryin to get the street of currAddress. In my code
> I do this way
>
> string strStreet="";
> FileStream fs = new
> FileStream(myXml.xml",FileMode.Open);
> XmlTextReader myReader = new XmlTextReader(fs);
> while(myReader.Read())
> {
>   if(myReader.NodeType != XmlNodeType.EndElement)
>   {
>     switch(myReader.Name)
>     {
>       case "street":
>          strStreet = myReader.ReadString();
>     }
>   }
> }
>
> How can I specify that I need only the
> currAddress/street
>
> Any help greatly appreciated.
>
> Thanks
> Nischal
>
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! - Official partner of 2002 FIFA World Cup
> http://fifaworldcup.yahoo.com
>
> You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
> subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to