Sample XML
<?xml version="1.0" encoding="UTF-8"?>
<Document>
<Report>
<Node>
<Detail>
<Id>1</Id>
<Value>Value 1</Value>
<Tag1>
<Owner>
<Id>
<INT>12345</INT>
</Id>
</Owner>
</Tag1>
</Detail>
<Status>
<Result>Pass</Result>
</Status>
</Node>
<Node>
<Detail>
<Id>2</Id>
<Value>Value 2</Value>
<Tag1>
<Owner>
<Id>
<String>TEST</String>
</Id>
</Owner>
</Tag1>
</Detail>
<Status>
<Result>Fail</Result>
</Status>
</Node>
<Node>
<Detail>
<Id>3</Id>
<Value>Value 3</Value>
<Tag1>
<Owner>
<Id>
<UN>UNKNOWN</UN>
</Id>
</Owner>
</Tag1>
</Detail>
<Status>
<Result>Waiting</Result>
</Status>
</Node>
</Report>
</Document>
Based on above structure, I want to read elements / attributes and populate POJO (XPath preferably) as element path is not consistent, e.g.: <Tag1>.
I'm not able to figure out how to proceed. I've tried using AutoPilot but it reads data sequentially, e.g. all Node Ids. I can't figure out a way to read all data within <Node> and then proceed to next one and so on. At the end I need to return populated POJO collection.
DOM is out of scope as XML file is huge, almost 800MB to 1GB in size with approx. 600,000+ <Node>.
Thanks in advance.
XML Reader
public void process(final String fullPath) {
try {
final VTDGen vg = new VTDGen();
if (vg.parseFile(fullPath, false)) {
final VTDNav vn = vg.getNav();
final AutoPilot ap = new AutoPilot(vn);
ap.selectXPath(ROOT);
while ((ap.evalXPath()) != -1) {
final AutoPilot pilot1 = new AutoPilot(vn);
pilot1.selectXPath(ROOT + "/Detail/Id");
while (pilot1.evalXPath() != -1) {
final int t = vn.getText();
if (t != -1) {
System.out.println(vn.toNormalizedString(t));
}
final AutoPilot pilot2 = new AutoPilot(vn);
pilot2.selectXPath(ROOT + "/Status/Result");
if (pilot2.evalXPath() != -1) {
final int k = vn.getText();
if (k != -1) {
System.out.println(vn.toNormalizedString(k));
}
}
// pilot2.resetXPath();
}
}
}
}
catch (Exception exception) {
}
}
I modified your code a bit to make it work... plus correcting a few things... will come back with more comments embedding in the code....
A few things to keep in mind
import com.ximpleware.*; public class sawi {
}