assistance to convert xml string to double

Last post 07-02-2008 4:47 AM by Samu Zhang - MSFT. 2 replies.

Sort Posts:

  • assistance to convert xml string to double

    06-28-2008, 4:59 AM

    Hi

    I have this in my code file right now:


    Partial Class courseTabs
        Inherits System.Web.UI.UserControl
     
      Public Function getDuration() As String
          Dim value As String = XPath("duration")
          Return String.Concat("<li><strong>Duration: ", value , "</strong>.</li>")
      End Function
     
       Public Function getMOPrice() As String
            Dim value As String = XPath("prices/price[@vehicle='mo']")
           If value Is Nothing Then
                 Return String.Empty
            Else
                Return String.Concat(" <li>Price: US$ ", value, ".00 per Student.")
             End If
        End Function
      
        
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
     
        End Sub
    End Class
     

    How do i convert getMOPrice to a double?  In this section i have added the unit info but in another section i wanted to take the value and multiply is by the sales tax = 18%.

    I found this on the msn site:    ' Dim returnValue As Decimal
      ' returnValue = XmlConvert.ToDecimal(s)

     

    but have no idea if it applies or how to apply it to my situation.

     This is the xml snippet:

     <product code="mo" name="MO Course">
          <duration>1 Day or 3 Days</duration>
          <visible>true</visible>
          <prices>
            <price vehicle="mo1">155</price>
            <price vehicle="mo3">465</price>
          </prices>
          <courseSummary>Stuff.</courseSummary>
          <courseUrl>link</courseUrl>
        </product>

    Any help is greatly appreciated.

    Thanks in advance.

    Tania

  • Re: assistance to convert xml string to double

    06-28-2008, 7:28 AM
    • Loading...
    • AndreiH
    • Joined on 01-21-2008, 4:04 PM
    • Bucharest
    • Posts 150
    Use Val(expression) - will always convert to a double, and never generate run-times.
    Best regards,
    Andrei
  • Re: assistance to convert xml string to double

    07-02-2008, 4:47 AM
    Answer

    Hi taniafarmer ,

    I think the Class Convert will help.

     

            string str = "mo1";
            XmlDocument doc = new XmlDocument();
            doc.Load(Server.MapPath("XMLFile69.xml"));
            XmlNode node = doc.SelectSingleNode("//price[@vehicle = '"+str +"']");
            double val = Convert.ToDouble(node.InnerText);
     
    Sincerely,
    Samu Zhang
    Microsoft Online Community Support

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
Page 1 of 1 (3 items)
Microsoft Communities
Page view counter