T
Tony Clark
Hi,
I have an app that write out form deatils to an xml file (e.g. its caption,
size ect). Heres the xml output;-
---------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<forms>
<form>
<title>ddd</title>
<height>138</height>
<width>174</width>
<xLoc>660</xLoc>
<yLoc>181</yLoc>
</form>
<form>
<title>sss</title>
<height>138</height>
<width>174</width>
<xLoc>522</xLoc>
<yLoc>235</yLoc>
</form>
<form>
<title>aaa</title>
<height>138</height>
<width>174</width>
<xLoc>290</xLoc>
<yLoc>127</yLoc>
</form>
</forms>
---------------------------------------------------------
Now when i read the xml it does not seem to read all the data, it seems to
either miss bits or reads bits into the wrong place, heres the code;-
---------------------------------------------------------
XmlTextReader formReader = new XmlTextReader("forms.xml");
string title=null;
string data = null;
string xloc = null;
string yloc = null;
string width = null;
string height = null;
bool bTitle=false;
bool bHeight=false;
bool bWidth=false;
bool bXloc=false;
bool bYloc=false;
bool done = false;
while (formReader.Read())
{
switch (formReader.NodeType)
{
case XmlNodeType.Element:
if (formReader.Name.Equals("form"))
{
title = data = xloc = yloc = height = width = null;
}
else if (formReader.Name.Equals("title"))
{
bTitle = true;
}
else if (formReader.Name.Equals("xLoc"))
{
bXloc = true;
}
else if (formReader.Name.Equals("yLoc"))
{
bYloc = true;
}
else if (formReader.Name.Equals("width"))
{
bWidth = true;
}
else if (formReader.Name.Equals("height"))
{
bHeight = true;
}
break;
case XmlNodeType.Text:
if (bTitle)
{
title = formReader.ReadString();
bTitle = false;
}
if (bHeight)
{
height = formReader.ReadString();
bHeight = false;
}
if (bWidth)
{
width = formReader.ReadString();
bWidth = false;
}
if (bXloc)
{
xloc = formReader.ReadString();
bXloc = false;
}
if (bYloc)
{
yloc = formReader.ReadString();
bYloc = false;
done = true;
}
break;
default:
break
}
if (done)
{
this.newForm(title, int.Parse(height), int.Parse(width),
int.Parse(xloc), int.Parse(yloc));
done = false;
}
}
formReader.Close();
}
-------------------------------------------
excuse the messy code! What am i doing wrong?
thanks in advance
I have an app that write out form deatils to an xml file (e.g. its caption,
size ect). Heres the xml output;-
---------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<forms>
<form>
<title>ddd</title>
<height>138</height>
<width>174</width>
<xLoc>660</xLoc>
<yLoc>181</yLoc>
</form>
<form>
<title>sss</title>
<height>138</height>
<width>174</width>
<xLoc>522</xLoc>
<yLoc>235</yLoc>
</form>
<form>
<title>aaa</title>
<height>138</height>
<width>174</width>
<xLoc>290</xLoc>
<yLoc>127</yLoc>
</form>
</forms>
---------------------------------------------------------
Now when i read the xml it does not seem to read all the data, it seems to
either miss bits or reads bits into the wrong place, heres the code;-
---------------------------------------------------------
XmlTextReader formReader = new XmlTextReader("forms.xml");
string title=null;
string data = null;
string xloc = null;
string yloc = null;
string width = null;
string height = null;
bool bTitle=false;
bool bHeight=false;
bool bWidth=false;
bool bXloc=false;
bool bYloc=false;
bool done = false;
while (formReader.Read())
{
switch (formReader.NodeType)
{
case XmlNodeType.Element:
if (formReader.Name.Equals("form"))
{
title = data = xloc = yloc = height = width = null;
}
else if (formReader.Name.Equals("title"))
{
bTitle = true;
}
else if (formReader.Name.Equals("xLoc"))
{
bXloc = true;
}
else if (formReader.Name.Equals("yLoc"))
{
bYloc = true;
}
else if (formReader.Name.Equals("width"))
{
bWidth = true;
}
else if (formReader.Name.Equals("height"))
{
bHeight = true;
}
break;
case XmlNodeType.Text:
if (bTitle)
{
title = formReader.ReadString();
bTitle = false;
}
if (bHeight)
{
height = formReader.ReadString();
bHeight = false;
}
if (bWidth)
{
width = formReader.ReadString();
bWidth = false;
}
if (bXloc)
{
xloc = formReader.ReadString();
bXloc = false;
}
if (bYloc)
{
yloc = formReader.ReadString();
bYloc = false;
done = true;
}
break;
default:
break
}
if (done)
{
this.newForm(title, int.Parse(height), int.Parse(width),
int.Parse(xloc), int.Parse(yloc));
done = false;
}
}
formReader.Close();
}
-------------------------------------------
excuse the messy code! What am i doing wrong?
thanks in advance