Read double value from XML

In this chapter you will learn:

  1. How to use XmlReader to read double value from xml

Read double value out

using System;/*from  ja v a 2  s.  c  o m*/
using System.Data;
using System.Text;
using System.Xml;

public class MainClass
{
    public static void Main()
    {
        XmlReader reader;
        double totalPrice=0;
        
        reader = XmlReader.Create("pubs.xml");
        while (reader.Read())
        {
            if (reader.IsStartElement() && reader.Name=="titles")
            {
                reader.MoveToAttribute("price");
                totalPrice += reader.ReadContentAsDouble();
            }
        }
    }
}

Next chapter...

What you will learn in the next chapter:

  1. How to read xml from a URL
Home » C# Tutorial » XML
Parse XML file
Parse XML String
Parse XML from URL
Element create
Attribute create
Comments create
XProcessingInstruction
XmlReader
Read double value from XML
XmlReader
XmlReaderSettings
XML formatter
XmlSerializer
XmlTextReader
XmlTextWriter
XmlWriter
XmlWriterSettings
Output XML to console