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 / Languages / C# / March 2006

Tip: Looking for answers? Try searching our database.

XML Schmell !!!

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tony Clark - 17 Mar 2006 23:02 GMT
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
Cerebrus - 18 Mar 2006 07:44 GMT
Hi,

It seems to work for me, though I had to change the this.NewForm()
part. What bits and parts are you missing ?

Regards,

Cerebrus.

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.