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 / August 2005

Tip: Looking for answers? Try searching our database.

ReadOuterXml Locks Up

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
TJO - 30 Aug 2005 01:12 GMT
The following code snippet seems to successfully read the first
outerxml but on the second time in the loop it locks up.  Can anyone
see why?

Thanks

<code snippet>

using (FileStream fs = File.Open(test._LogFileName,
FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None))
{
reader = new XmlTextReader(fs);

while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
  if (reader.Name.Equals("MITest"))
  {
     stringBuilder.Append(reader.ReadOuterXml()); // locks up here
when reading the second MITest element
  }
}
}
}
</code snippet>

<XMLFileBeingRead>

<MITest Test="Nothing Test" Object="Foo">
 <StartTime>8/29/2005 4:50:12 PM</StartTime>
 <EndTime>8/29/2005 4:50:13 PM</EndTime>
 <Result>TimeOut</Result>
</MITest>
<MITest Test="Nothing Test" Object="Foo">
 <StartTime>8/29/2005 4:50:29 PM</StartTime>
 <EndTime>8/29/2005 4:50:30 PM</EndTime>
 <Result>TimeOut</Result>
</MITest>

</XMLFileBeingRead>
TJO - 30 Aug 2005 03:11 GMT
Actually it is locking up on the firs call to ReadOuterXml when when
two or mowe MITest elements exists in the xml file.
TJO - 30 Aug 2005 03:25 GMT
I was using the SystemInternal FileMon program to watch the XML file as
my program ran and noticed a buffer overflow entry:

7:22:10 PM    TestClassTester:1424    QUERY
INFORMATION    C:\STProjects\Projects\SmartMI\TestClassTester\bin\Debug\NothingTestLog_Foo.xml    BUFFER
OVERFLOW    FileFsVolumeInformation
Oleg Tkachenko [MVP] - 30 Aug 2005 08:33 GMT
> reader = new XmlTextReader(fs);
>
[quoted text clipped - 6 lines]
>       stringBuilder.Append(reader.ReadOuterXml()); // locks up here
> when reading the second MITest element

Well, it works for me, but I see the problem here. Beware that after
reader.ReadOuterXml() call the reader is positioned at the next node
*after* </MITest>. If it's whitespace - it works, if that's next
<MITest> start tag - you loses it by calling reader.Read() in while
statement. In such cases the loop better be implemented using
!reader.EOF as invariant:
while (!reader.EOF)
{
  if (reader.NodeType == XmlNodeType.Element &&
reader.Name.Equals("MITest"))
  {                       
    Console.WriteLine(reader.ReadOuterXml());                    
  }                    
  else
  {                        
    reader.Read();
  }
}

Signature

Oleg Tkachenko [XML MVP, MCAD]
http://www.xmllab.net
http://blog.tkachenko.com

TJO - 30 Aug 2005 15:06 GMT
Thanks Oleg,
I suspected it was something like this but my sample still fails after
modifying my code to look like yours.

The failure still fails on the second time the reader.ReadOutXml() line
is reached in the loop.  The strange thing is that it is not really a
failure as in the program crashes.  It just hangs there.

So I remain stuck :(

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.