Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / May 2005

Tip: Looking for answers? Try searching our database.

XMLTextReader - jump to beginning

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Newton - 25 Apr 2005 13:01 GMT
Hi,

  I receive XML document from input and I would like to read it several
times...
My declaration is
    XmlTextReader XMLInputReader =
        new XmlTextReader(fileImport.PostedFile.InputStream);

  I am reading it like this

while (XMLInputReader.Read())
{
//code
}

After this loop I am at the end of XMLInputReader but I would like to be at
the beginning of that reader because I need to use that loop for reading
again...
How can I make it?

Thanks for your responses...
Martin Honnen - 25 Apr 2005 13:50 GMT
>    I receive XML document from input and I would like to read it several
> times...
[quoted text clipped - 12 lines]
> the beginning of that reader because I need to use that loop for reading
> again...

XmlTextReader is a fast forward only pull parser.
If you want to navigate back and forth then an XPathDocument
respectively an XPathNavigator created from that can help.

Signature

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/

Newton - 25 Apr 2005 14:14 GMT
Martin, I will try to look at it...

still one more question... I tried to create another XMLTextReader object
and simply put the content of old one to this new one. But I need copy of
whole content. So in that case I can read from both readers from the
beginning. Could you advice how to make it?

Something like this:
XmlTextReader XMLInputReader =
         new XmlTextReader(fileImport.PostedFile.InputStream);

XmlTextReader XMLInputReader2 = XMLInputReader;
         
but it should also work...

thanks
Oleg Tkachenko [MVP] - 01 May 2005 11:12 GMT
> Martin, I will try to look at it...
>
[quoted text clipped - 6 lines]
> XmlTextReader XMLInputReader =
>           new XmlTextReader(fileImport.PostedFile.InputStream);

Isn't PostedFile.InputStream a reusable stream? Can't you just create
anothe reader the same way?
If no - read the whole PostedFile.InputStream content into temporary
MemoryStream and reuse it.

Signature

Oleg Tkachenko [XML MVP, MCP]
http://blog.tkachenko.com


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.