- vtd-xml_ii.zip
- app2
- example1
- example2
- example3
- example4
- example5
- example6
|
using System.IO;
using System.Collections.Generic;
using System.Text;
using com.ximpleware;
namespace example4
{
class Program
{
static void Main(string[] args)
{
AutoPilot ap1 = new AutoPilot();
AutoPilot ap2 = new AutoPilot();
AutoPilot ap3 = new AutoPilot();
ap1.selectXPath("/root/a");
ap2.selectXPath("/root/b");
ap3.selectXPath("/root/c");
byte[] ba1, ba2, ba3;
VTDGen vg = new VTDGen();
Encoding eg = System.Text.Encoding.GetEncoding("utf-8");
if (vg.parseFile("D:/codeProject/app2/example4/example4/input.xml", false))
{
VTDNav vn = vg.getNav();
ap1.bind(vn);
ap2.bind(vn);
ap3.bind(vn);
FileStream fos = new FileStream("D:/codeProject/app2/example4/example4/new.xml",
System.IO.FileMode.OpenOrCreate);
ba1 = eg.GetBytes("<root>");
ba2 = eg.GetBytes("</root>");
ba3 = eg.GetBytes("\r\n");
byte[] ba = vn.getXML().getBytes();
fos.Write(ba1, 0, ba1.Length);
while (ap1.evalXPath() != -1)
{
long l = vn.getElementFragment();
int offset = (int)l;
int len = (int)(l >> 32);
fos.Write(ba3, 0, ba3.Length);
fos.Write(ba, offset, len);
}
// resetXPath is good if you want to reuse it
ap1.resetXPath();
while (ap2.evalXPath() != -1)
{
long l = vn.getElementFragment();
int offset = (int)l;
int len = (int)(l >> 32);
fos.Write(ba3, 0, ba3.Length);
fos.Write(ba, offset, len);
}
ap2.resetXPath();
while (ap3.evalXPath() != -1)
{
long l = vn.getElementFragment();
int offset = (int)l;
int len = (int)(l >> 32);
fos.Write(ba3, 0, ba3.Length);
fos.Write(ba, offset, len);
}
ap3.resetXPath();
fos.Write(ba3, 0, ba3.Length);
fos.Write(ba2, 0, ba2.Length);
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Jimmy Zhang is a cofounder of XimpleWare, a provider of high performance XML processing solutions. He has working experience in the fields of electronic design automation and Voice over IP for a number of Silicon Valley high-tech companies. He holds both a BS and MS from the department of EECS from U.C. Berkeley.