Re: Exception error with XmlTextReader

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Aaron (ABieberitz_at_charter.net)
Date: 11/29/04


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
> >
> >
>
>



Relevant Pages

  • Re: Exception error with XmlTextReader
    ... trap the exception; ... >> string temp = xmlTr.ReadString.Trim; ... >>>> to numeric conversions in exception handling blocks in case the string ... >>>> Instead of a dynamic array, ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: No coercion in for-each loop?
    ... believer in explicitly marking conversions. ... Boolean (true/false) ... String ... Each has a standard value to which an empty node set automatically ...
    (comp.lang.java.programmer)
  • Re: Ada.Strings.Bounded
    ... for Unbounded_String'Conversion use To_String; ... Below you immediately spot the problem of conversions ... String'Class and you wanted to inherit everything form String. ... The implementation of inheritance (by the compiler) will require you to ...
    (comp.lang.ada)
  • Re: Fastest Date Sort
    ... So the whole program is done with String ... >>> But what kind of trouble could I be asking for? ... > default type conversions and formatting, ... and are best avoided by using explicit conversions. ...
    (comp.lang.basic.visual.misc)
  • Re: one-liner for characater replacement
    ... that whole can of worms about internal representations of LOGICALs ... Since a string is almost identical to a rank-1 ... No matter what INTEGER KIND is the ... So our hypothetical conversions between LOGICAL ...
    (comp.lang.fortran)