XmlReaderSettings

In this chapter you will learn:

  1. How to set up XmlReaderSettings to control the parsing

Set up XmlReaderSettings

using System;/*  j  a va 2  s.co m*/
using System.Collections.Generic;
using System.Data;
using System.Xml;
using System.Xml.Schema;

public class MainClass
{
    public static void Main()
    {
        XmlReaderSettings settings = new XmlReaderSettings();
        settings.ProhibitDtd = false;
        settings.ValidationType = ValidationType.DTD;
        //settings.ValidationType=ValidationType.Schema;
        //settings.Schemas.Add("", "");

        settings.ValidationEventHandler += new ValidationEventHandler(OnValidationError);

        XmlReader reader=XmlReader.Create("value", settings);
        while (reader.Read())
        {
        }
        reader.Close();
    }
    static void OnValidationError(object sender, ValidationEventArgs e)
    {
        MessageBox.Show(e.Message);
    }
}

Next chapter...

What you will learn in the next chapter:

  1. How to use XML formatter to format XML
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