Пример #1
0
 public static void Main(String[] args)
 {
     // instantiate VTDGen and XMLModifier
     VTDGen vg = new VTDGen();
     XMLModifier xm = new XMLModifier();
     AutoPilot ap = new AutoPilot();
     AutoPilot ap2 = new AutoPilot();
     ap.selectXPath("(/*/*/*)[position()>1 and position()<4]");
     ap2.selectXPath("/*/*/*");
     if (vg.parseFile("soap2.xml", true))
     {
         VTDNav vn = vg.getNav();
         xm.bind(vn);
         ap2.bind(vn);
         ap.bind(vn);
         ap2.evalXPath();
         ElementFragmentNs ef = vn.getElementFragmentNs();
         int i = -1;
         while ((i = ap.evalXPath()) != -1)
         {
             xm.insertAfterElement(ef);
         }
         xm.output("new_soap.xml");
     }
 }
Пример #2
0
        public static void Main(String[] args)
        {

            String xml = "<aaaa> <bbbbb> <ccccc> </ccccc> <ccccc/> <ccccc></ccccc> </bbbbb> </aaaa>";
            Encoding eg = Encoding.GetEncoding("utf-8");
            VTDGen vg = new VTDGen();
            vg.setDoc(eg.GetBytes(xml));
            vg.parse(false);
            VTDNav vn = vg.getNav();
            AutoPilot ap = new AutoPilot(vn);
            ap.selectXPath("//*");
            XMLModifier xm = new XMLModifier(vn);
            while (ap.evalXPath() != -1)
            {
                xm.updateElementName("d:/lalalala");
            }
            xm.output("lala.xml");
        }
Пример #3
0
 static void Main(string[] args)
 {
     try
     {
         // open a file and read the content into a byte array
         VTDGen vg = new VTDGen();
         if (vg.parseFile("./oldpo.xml", true))
         {
             VTDNav vn = vg.getNav();
             System.IO.FileInfo f1 = new System.IO.FileInfo("./newpo.txt");
             System.IO.FileStream fos = new System.IO.FileStream(f1.FullName, System.IO.FileMode.Create);
             
             AutoPilot ap = new AutoPilot(vn);
             XMLModifier xm = new XMLModifier(vn);
             ap.selectXPath("/purchaseOrder/items/item[@partNum='872-AA']");
             int i = -1;
             while ((i = ap.evalXPath()) != -1)
             {
                 xm.remove();
                 xm.insertBeforeElement("<something/>\n");
             }
             ap.selectXPath("/purchaseOrder/items/item/USPrice[.<40]/text()");
             while ((i = ap.evalXPath()) != -1)
             {
                 xm.updateToken(i, "200");
             }
             xm.output(fos);
             fos.Close();
         }
     }
     catch (NavException e)
     {
         Console.WriteLine(" Exception during navigation " + e);
     }
     catch (ModifyException e)
     {
         Console.WriteLine(" Modify exception occurred " + e);
     }
     catch (System.IO.IOException e)
     {
         System.Console.Out.WriteLine(" IO exception condition" + e);
     }
 }