Csharp/C Sharp by API/System.Xml/XmlReaderSettings

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

XmlReaderSettings.Schemas.Add

<source lang="csharp"> using System; using System.Collections.Generic; using System.ruponentModel; 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");
   }

}


 </source>


XmlReaderSettings.ValidationType

<source lang="csharp"> using System; using System.Collections.Generic; using System.ruponentModel; 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");
   }

}


 </source>