Re: Exception error with XmlTextReader
From: Aaron (ABieberitz_at_charter.net)
Date: 11/29/04
- Next message: Paul G. Tobey [eMVP]: "Re: Counting milliseconds on PPC"
- Previous message: Darren Shaffer: "Re: Transparent controls in CF 2.0?"
- In reply to: Darren Shaffer: "Re: Exception error with XmlTextReader"
- Next in thread: Daniel Moth: "Re: Exception error with XmlTextReader"
- Reply: Daniel Moth: "Re: Exception error with XmlTextReader"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 29 Nov 2004 14:16:51 -0600
I still get the same error even though I have changed the code as you
suggested (and I am also using ArrayLists as well:
parList.Add(Double.Parse(xmlTr.ReadString().Trim()));
"Darren Shaffer" <darrenshaffer@discussions.microsoft.com> wrote in message
news:OmnojQk1EHA.2804@TK2MSFTNGP15.phx.gbl...
> Aaron,
>
> The code causing your exception is probably:
> System.Convert.ToDouble(xmlTr.ReadString());
> which may be failing on some string value in your XML file.
>
> Try Double.Parse(xmlTr.ReadString()) and always put string
> to numeric conversions in exception handling blocks in case the string
> cannot be converted. Also a good idea to trim the string you
> get out of the XML file before conversion.
>
> Instead of a dynamic array, I'd recommend using an ArrayList
> for performance reasons.
>
> -Darren Shaffer
>
> "Aaron" <ABieberitz@charter.net> wrote in message
> news:kcJqd.108$0s4.59@fe04.lga...
> > Why am I getting the following error:
> >
> > "An unhandled exception of type 'System.FormatException' occured in
> > mscorlib.dll"
> >
> > from this code:
> >
> > string[] medicationList = new string[14];
> > double[] parenteralValues = new double[14];
> > double[] oralValues = new double[14];
> >
> > private void GetValues()
> > {
> > String xmlFile = "Program Files\\C-Tools\\pnmd.xml";
> > int arrayCount = 0;
> >
> > XmlTextReader xmlTr = new XmlTextReader(xmlFile);
> > while (xmlTr.Read())
> > {
> > switch(xmlTr.Name)
> > {
> > case "Drug":
> > if (xmlTr.NodeType == XmlNodeType.Element)
> > medicationList[arrayCount] = xmlTr.ReadString();
> > break;
> > case "Parenteral":
> > if (xmlTr.NodeType == XmlNodeType.Element)
> > parenteralValues[arrayCount] =
> > System.Convert.ToDouble(xmlTr.ReadString());
> > break;
> > case "Oral":
> > if (xmlTr.NodeType == XmlNodeType.Element)
> > oralValues[arrayCount] =
System.Convert.ToDouble(xmlTr.ReadString());
> > break;
> > default:
> > break;
> > }
> > arrayCount += 1;
> > }
> > xmlTr.Close();
> > }
> >
> > Here's my xml structure:
> >
> > <?xml version="1.0" encoding="utf-8" ?>
> > <Pain_Medications>
> > <Medications>
> > <Drug>Codeine</Drug>
> > <Parenteral>130.00</Parenteral>
> > <Oral>200.00</Oral>
> > <Comment>Codeine is usually combined with Tylenol or aspirin, and that
is
> > the limiting factor in the dosage of this drug.
> > </Medications>
> > </Pain_Medications>
> >
> > Also, if someone could tell my how to make the arrays dynamic since I
> > won't
> > be having a static amount of records, the above 14 was just for testing
> > purposes.
> >
> > Thanks
> >
> >
>
>
- Next message: Paul G. Tobey [eMVP]: "Re: Counting milliseconds on PPC"
- Previous message: Darren Shaffer: "Re: Transparent controls in CF 2.0?"
- In reply to: Darren Shaffer: "Re: Exception error with XmlTextReader"
- Next in thread: Daniel Moth: "Re: Exception error with XmlTextReader"
- Reply: Daniel Moth: "Re: Exception error with XmlTextReader"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|