Select by path

image_pdfimage_print
   
 

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();
        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");
    }
}  
           
         
     


This entry was posted in XML-RPC. Bookmark the permalink.