Csharp/C Sharp by API/System.Xml.XPath/XPathNodeIterator

Материал из .Net Framework эксперт
Версия от 12:11, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

XPathNodeIterator.Current.InsertAfter

  
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();
        doc.Load("books.xml");
        XPathNavigator nav = doc.CreateNavigator();
        if (nav.CanEdit) {
            XPathNodeIterator iter = nav.Select("/bookstore/book/price");
            while (iter.MoveNext()) {
                iter.Current.InsertAfter("<disc>5</disc>");
            }
        }
        doc.Save("newbooks.xml");
    }
}


XPathNodeIterator.Current.SelectDescendants

  

using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Xml;
using System.Xml.XPath;
public class MainClass {
    public static void Main() {
        XPathDocument doc = new XPathDocument("books.xml");
        XPathNavigator nav = ((IXPathNavigable)doc).CreateNavigator();
        XPathNodeIterator iter = nav.Select("/bookstore/book[@genre="novel"]");
        while (iter.MoveNext()) {
            XPathNodeIterator newIter = iter.Current.SelectDescendants(XPathNodeType.Element, false);
            while (newIter.MoveNext())
                Console.WriteLine(newIter.Current.Name + ": " + newIter.Current.Value);
        }
    }
}


XPathNodeIterator.MoveNext()

  
using System;
using System.Data;
using System.Xml;
using System.Xml.XPath;
public class MainClass  {
  public static void Main() {
      XPathDocument doc = new XPathDocument( "sample.xml" );
      XPathNavigator nav = doc.CreateNavigator();
      XPathExpression xpe = nav.rupile( "//name" );
      XPathNodeIterator ni = nav.Select( xpe );
  
      while ( ni.MoveNext() ) {
          Console.WriteLine(ni.Current.Value);
      }
  }
}