I have the school data in xml file as structured below.
<?xml version="1.0" encoding="ISO-8859-1"?>
<SchoolData>
<School>
<ScId>SC101-91</ScId>
<Location>
<Branch>
<BranchId>Br-111</BranchId>
<Type>Residential</Type>
<RealType>Residential</RealType>
</Branch>
<Branch>
<BranchId>BR-222</BranchId>
<Type>Daycare</Type>
<RealType>Daycare</RealType>
</Branch>
<Branch>
<BranchId>Br-333</BranchId>
<Type>Unknown</Type>
<RealType>Unknown</RealType>
</Branch>
</Location>
</School>
<School>
<ScId>RC101-92</ScId>
<Location>
<Branch>
<BranchId>Br-111</BranchId>
<Type>Residential</Type>
<RealType>Residential</RealType>
</Branch>
<Branch>
<BranchId>BR-222</BranchId>
<Type>Daycare</Type>
<RealType>Daycare</RealType>
</Branch>
<Branch>
<BranchId>Br-333</BranchId>
<Type>Unknown</Type>
<RealType>Unknown</RealType>
</Branch>
</Location>
</School>
</SchoolData>
I am filtering all the school nodes based on a condition using xpath expression as /*/School[starts-with(ScId,'RC')]
While I am iterating over each school node, I need to create branch object based on the type.
I have made the xpath expression for the same but not sure how to implement using VTD.
I have following parser code and unable to select the branch node and create respective branch object.
public static void main(String[] args) throws XPathParseExceptionHuge, XPathEvalExceptionHuge, NavExceptionHuge, NavException, XPathParseException, XPathEvalException {
String xpath = "/*/School[starts-with(ScId,'RC')]";
String xml = "config/school.xml";
final VTDGenHuge vg = new VTDGenHuge();
System.out.println("Parsing");
vg.parseFile(xml, true, VTDGenHuge.MEM_MAPPED);
VTDNavHuge vn = vg.getNav();
AutoPilotHuge aph = new AutoPilotHuge(vn);
aph.selectXPath(xpath);
while ((aph.evalXPath()) != -1) {
String childXpath = "/*/School[starts-with(ScId,'RC')]/Location/Branch/[Type = 'Residential']";
Branch br1 = new Branch();
br1.setRealType(""); // get the value from the 'Branch' child node of this school node
}
}