Set XmlReaderSettings : Schema « XML « C# / C Sharp






Set XmlReaderSettings

   


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Xml.XPath;

public class MainClass {
    public static void Main() {
        XmlDocument doc = new XmlDocument();
        XmlReaderSettings rs = new XmlReaderSettings();
        rs.Schemas.Add(null, "books.xsd");
        rs.ValidationType = ValidationType.Schema;
        XmlReader rdr = XmlReader.Create("books.xml", rs);
        doc.Load(rdr);

        XPathNavigator nav = doc.CreateNavigator();

        if (nav.CanEdit) {
            XPathNodeIterator iter = nav.Select("/bookstore/book/price");
            while (iter.MoveNext()) {
                iter.Current.SetTypedValue("Invalid");
            }
        }
        doc.Save("newbooks.xml");

    }
}

           
         
    
    
  








Related examples in the same category

1.Choose ValidationType
2.Validate an XML Document Against a Schema
3.Validate Schema
4.Use XML schema to validate XML documents
5.Use XmlReaderSettings to validate the Xml document
6.Strip Non Valid XML Characters.
7.Is Well Formed Xml
8.XmlSchema is an in-memory representation of an XML Schema
9.Is Xml Valid
10.Xml Validation Helper
11.Get Intrinsic Simple Types Names from System.Xml.Schema.DatatypeImplementation
12.Reads a XML schema file and returns the information found in that.
13.XML reading functionality