The following code will enter an infinate loop when in ReadChars. I can only
make it happen when reading a Stream and with this particular XML. If I use
the ReadInnerXml call rather than my own ReadElementBody AsXml the code works,
but is less efficent. ReadElementBody AsXml is required by my application
with .Net Framework 1.1.
The code breaks on the second call to ReadElementBody AsXml with the inner xml:
</EGDConfigExtens ion>
<EGDConfigExten sion Company="http://pdweb.salem.ge. com"
ExtensionCode=" MasterHmiResour ces"><HmiResour ces>
<HmiResource Name="hgyugyg" />
</HmiResources></EGDConfigExtens ion>
This is bad behavior, so I felt it should be posted. Maybe it is already
know to be fixed in SP1 (hopefully forthcoming).
Regards,
Rick
--- code that breaks ---
private void ReadXml()
{
FileStream fs = File.OpenRead(@ "MasterSymbolTa ble.xml");
XmlTextReader reader = new XmlTextReader(f s, XmlNodeType.Ele ment, null);
reader.MoveToCo ntent();
reader.ReadToDe scendant("EGDCo nfigExtension") ;
string xml = ReadElementBody AsXml(reader);
reader.Read();
xml = ReadElementBody AsXml(reader);
}
private string ReadElementBody AsXml(XmlTextRe ader reader)
{
int startingLineNum ber = reader.LineNumb er;
int startingLinePos ition = reader.LinePosi tion;
int startingDepth = reader.Depth;
bool startingElement IsEmpty = reader.IsEmptyE lement;
string startingName = reader.Name;
System.Diagnost ics.Debug.Asser t(reader.NodeTy pe == XmlNodeType.Ele ment,
"Node type must be Element.",
"ReadElementBod yAsXml should be called when the reader is positioned on
an element. It will simply return null if it is not, but the intention is
for it to be used to read element content.");
char[] buffer = new char[512];
int totalRead = 0;
int i;
while ((i = reader.ReadChar s(buffer, totalRead, buffer.Length -
totalRead)) 0)
{
totalRead += i;
if (reader.Depth <= startingDepth)
{
// Even though we read chars, the LineNumber and LinePosition do not
change
// unless we read a node. We don't want to read any more unless we are
// on a child node. But we also need to make sure that we are not still
// on the same node that we started with, since we could have some very
// big nodes. It is hard to tell if ReadChars returned because it did
// not have any more content buffered or if it got to the end of a node.
// If at the end of a node, which node?
// This code fixes SCR 2923.
if (reader.NodeTyp e != XmlNodeType.Ele ment)
break; // We must not be on the node we started on.
}
if (reader.NodeTyp e == XmlNodeType.End Element && reader.Depth ==
startingDepth)
break;
if (totalRead == buffer.Length)
{
char[] newBuf = new char[buffer.Length + 512];
Buffer.BlockCop y(buffer, 0, newBuf, 0, totalRead * 2); // Each char is
2 bytes.
buffer = newBuf;
}
}
string innerXml = null;
if (totalRead 0)
innerXml = new string(buffer, 0, totalRead);
else
innerXml = null;
return innerXml;
}
----- XML file MasterSymbolTab le.Xml ---
<?xml version="1.0" encoding="utf-8"?>
<?GeCssClass type="GeIndsysN etworkCoe.EgdCo nfig.EgdMasterS ymbolTable,
EgdCoeConfig"?>
<MasterEgdSymbo lTable EGDSpecVersion= "3.04" ConfigTimeSecs= "1160762827 "
ConfigTimeNSecs ="704238500" xmlns="http://geindustrial.co m/EGD" Name="Demo">
<EGDConfigExten sion Company="http://pdweb.salem.ge. com"
ExtensionCode=" MasterAlarms">< AlarmClasses>
<AlarmClass Name="Alarm" Description="De fault Class for Process Alarms"
DescAlt="" NormalBackgroun dColor="White" NormalForegroun dColor="Black"
AlarmBackground Color="Red" AlarmForeground Color="White"
AckBackgroundCo lor="White" AckForegroundCo lor="Red" IsIntrinsic="tr ue"
NormalSeverity= "350" ActiveSeverity= "500" />
<AlarmClass Name="Trip" Description="De fault Class for Convertor Trips"
DescAlt="" NormalBackgroun dColor="White" NormalForegroun dColor="Black"
AlarmBackground Color="Maroon" AlarmForeground Color="White"
AckBackgroundCo lor="White" AckForegroundCo lor="Maroon" IsIntrinsic="tr ue"
NormalSeverity= "350" ActiveSeverity= "500" />
<AlarmClass Name="System" Description="De fault Class for WorkstationST
System alarms" DescAlt="" NormalBackgroun dColor="White"
NormalForegroun dColor="Black" AlarmBackground Color="Teal"
AlarmForeground Color="White" AckBackgroundCo lor="White"
AckForegroundCo lor="Teal" IsIntrinsic="tr ue" NormalSeverity= "350"
ActiveSeverity= "500" />
<AlarmClass Name="Diagnosti c" Description="De fault Class for Process
Diagnostics" DescAlt="" NormalBackgroun dColor="White"
NormalForegroun dColor="Black" AlarmBackground Color="Red"
AlarmForeground Color="White" AckBackgroundCo lor="White"
AckForegroundCo lor="Red" IsIntrinsic="tr ue" NormalSeverity= "350"
ActiveSeverity= "500" />
<AlarmClass Name="Hold" Description="De fault Class for Holds" DescAlt=""
NormalBackgroun dColor="White" NormalForegroun dColor="Black"
AlarmBackground Color="Yellow" AlarmForeground Color="Black"
AckBackgroundCo lor="Black" AckForegroundCo lor="Yellow" IsIntrinsic="tr ue"
NormalSeverity= "350" ActiveSeverity= "500" />
<AlarmClass Name="Diag" Description="De fault Class for Process Diagnostics"
DescAlt="" NormalBackgroun dColor="White" NormalForegroun dColor="Black"
AlarmBackground Color="Red" AlarmForeground Color="White"
AckBackgroundCo lor="White" AckForegroundCo lor="Red" IsIntrinsic="tr ue"
NormalSeverity= "350" ActiveSeverity= "500" />
<AlarmClass Name="Sys" Description="De fault Class for WorkstationST System
alarms" DescAlt="" NormalBackgroun dColor="White"
NormalForegroun dColor="Black" AlarmBackground Color="Teal"
AlarmForeground Color="White" AckBackgroundCo lor="White"
AckForegroundCo lor="Teal" IsIntrinsic="tr ue" NormalSeverity= "350"
ActiveSeverity= "500" />
<AlarmClass Name="TEST" Description="Te st Alarm Class" DescAlt=""
NormalBackgroun dColor="White" NormalForegroun dColor="Black"
AlarmBackground Color="Maroon" AlarmForeground Color="White"
AckBackgroundCo lor="White" AckForegroundCo lor="Maroon" NormalSeverity= "350"
ActiveSeverity= "500" />
<AlarmClass Name="OpSet" Description="Al arm Class for Operator Setpoint
Events" DescAlt="" NormalBackgroun dColor="White"
NormalForegroun dColor="Black" AlarmBackground Color="Yellow"
AlarmForeground Color="Black" AckBackgroundCo lor="Black"
AckForegroundCo lor="Yellow" IsIntrinsic="tr ue" NormalSeverity= "350"
ActiveSeverity= "500" />
<AlarmClass Name="SOE" Description="De fault Class for Sequence of event"
DescAlt="" NormalBackgroun dColor="White" NormalForegroun dColor="Black"
AlarmBackground Color="Yellow" AlarmForeground Color="Black"
AckBackgroundCo lor="Black" AckForegroundCo lor="Yellow" IsIntrinsic="tr ue"
NormalSeverity= "350" ActiveSeverity= "500" />
<AlarmClass Name="Event" Description="De fault Class for Process Events"
DescAlt="" NormalBackgroun dColor="White" NormalForegroun dColor="Black"
AlarmBackground Color="Yellow" AlarmForeground Color="Black"
AckBackgroundCo lor="Black" AckForegroundCo lor="Yellow" IsIntrinsic="tr ue"
NormalSeverity= "350" ActiveSeverity= "500" />
</AlarmClasses></EGDConfigExtens ion>
<EGDConfigExten sion Company="http://pdweb.salem.ge. com"
ExtensionCode=" MasterHmiResour ces"><HmiResour ces>
<HmiResource Name="hgyugyg" />
</HmiResources></EGDConfigExtens ion>
<EGDConfigExten sion Company="http://pdweb.salem.ge. com"
ExtensionCode=" MasterPlantArea s"><PlantAre as>
<PlantAreaPat h Path="Plant" />
<PlantAreaPat h Path="Plant.Pla ntArea01" />
<PlantAreaPat h Path="Plant.Pla ntArea01.PlantA rea21" />
<PlantAreaPat h Path="Plant.Pla ntArea02" />
<PlantAreaPat h Path="Plant.Pla ntArea04" />
<PlantAreaPat h Path="Plant.Pla ntArea14" />
<PlantAreaPat h Path="Plant.Pla ntArea15" />
</PlantAreas></EGDConfigExtens ion>
</MasterEgdSymbol Table>