/** * Test whether current element has an attribute with the matching name. "*" * will match any attribute name, therefore is a test whether there is any * attribute at all if namespace is disabled, this function will not * distinguish between ns declaration and attribute otherwise, ns tokens are * invisible Creation date: (11/16/03 5:50:26 PM) * * @return boolean (true if such an attribute exists) * @param an * java.lang.String * @exception com.ximpleware.NavException * The exception if the underlying byte content contains * various errors. Notice that we are being conservative in * making little assumption on the correctness of underlying * byte content. This is because the VTD etc can be generated * by another machine from a load-balancer. * @exception IllegalArguementException * if an is null */ final public boolean hasAttr(String an) throws NavException { return getAttrVal(an)!=-1; } /**
} else { ft = false; int i = vn.getAttrVal(name); if(i!=-1){
/** * Test whether current element has an attribute with the matching name. "*" * will match any attribute name, therefore is a test whether there is any * attribute at all if namespace is disabled, this function will not * distinguish between ns declaration and attribute otherwise, ns tokens are * invisible Creation date: (11/16/03 5:50:26 PM) * * @return boolean (true if such an attribute exists) * @param an * java.lang.String * @exception com.ximpleware.NavException * The exception if the underlying byte content contains * various errors. Notice that we are being conservative in * making little assumption on the correctness of underlying * byte content. This is because the VTD etc can be generated * by another machine from a load-balancer. * @exception IllegalArguementException * if an is null */ final public boolean hasAttr(String an) throws NavException { return getAttrVal(an)!=-1; } /**
/** * Test whether current element has an attribute with the matching name. "*" * will match any attribute name, therefore is a test whether there is any * attribute at all if namespace is disabled, this function will not * distinguish between ns declaration and attribute otherwise, ns tokens are * invisible Creation date: (11/16/03 5:50:26 PM) * * @return boolean (true if such an attribute exists) * @param an * java.lang.String * @exception com.ximpleware.NavException * The exception if the underlying byte content contains * various errors. Notice that we are being conservative in * making little assumption on the correctness of underlying * byte content. This is because the VTD etc can be generated * by another machine from a load-balancer. * if an is null */ final public boolean hasAttr(String an) throws NavException { return getAttrVal(an)!=-1; } /**
private Map<String, List<Integer>> getReferencedXmiIds(VTDNav vn, String typeName, TypeSystem ts) throws NavException { if (typeName.equals(CAS_NULL) || typeName.equals(CAS_VIEW)) return Collections.emptyMap(); Map<String, List<Integer>> referencesByFeatureBaseName = new HashMap<>(); Type annotationType = ts.getType(typeName); Function<String, List<Integer>> refAttributeValue2Integers = referenceString -> Stream.of(referenceString).filter(StringUtils::isNotBlank).map(refStr -> refStr.split("\\s+")).flatMap(Stream::of).map(Integer::parseInt).collect(toList()); if (isFSArray(annotationType)) { String referenceString = vn.toRawString(vn.getAttrVal("elements")); referencesByFeatureBaseName.put("elements", refAttributeValue2Integers.apply(referenceString)); } else if (!isFSArray(annotationType)) { List<Feature> features = annotationType.getFeatures(); for (Feature f : features) { Type featureType = f.getRange(); if (isFSArray(featureType) || !isPrimitive(featureType)) { int attributeIndex = vn.getAttrVal(f.getShortName()); if (attributeIndex >= 0) { String referenceString = vn.toRawString(attributeIndex); referencesByFeatureBaseName.put(f.getShortName(), refAttributeValue2Integers.apply(referenceString)); } } } } return referencesByFeatureBaseName; }
import com.ximpleware.*; public class queryAttr { public static void main(String[] s) throws VTDException{ VTDGen vg = new VTDGen(); vg.selectLcDepth(5);// improve XPath performance for deep document if (!vg.parseFile("input.xml", false)) return; VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("/BatchItemFullInfoAnswer/Result/Item/ConfiguredItems/OtapiConfiguredItem/Configurators/ValuedConfigurator"); int i=0,j=0; while((i=ap.evalXPath())!=-1){ j= vn.getAttrVal("pid"); if (j!=-1) System.out.println(" attr value for pid is ==>"+vn.toString(j)); j= vn.getAttrVal("vid"); if (j!=-1) System.out.println(" attr value for vid is ==>"+vn.toString(j)); } } }
String tableName = vn.toString(vn.getAttrVal("name")); String name = vn.toString(vn.getAttrVal("name"));
String tableName = vn.toString(vn.getAttrVal("name")); String name = vn.toString(vn.getAttrVal("name"));
private Map<Integer, JeDISVTDGraphNode> createJedisNodes(VTDNav vn, Map<String, String> namespaceMap, JCas aCas) throws VTDException { Map<Integer, JeDISVTDGraphNode> nodesByXmiId = new HashMap<>(); currentSecondSofaMapKey = SECOND_SOFA_MAP_KEY_START; vn.toElement(VTDNav.FIRST_CHILD); vn.toElement(VTDNav.FIRST_CHILD); do { Integer xmiIdIndex = vn.getAttrVal("xmi:id"); if (xmiIdIndex >= 0) { int i = vn.getCurrentIndex(); int oldXmiId = Integer.parseInt(vn.toRawString(xmiIdIndex)); String typeName = getTypeName(vn, namespaceMap, i); JeDISVTDGraphNode n = nodesByXmiId.computeIfAbsent(oldXmiId, typeName.equals(CAS_SOFA) ? SofaVTDGraphNode::new : JeDISVTDGraphNode::new); n.setElementFragment(vn.getElementFragment()); n.setTypeName(typeName); int sofaAttrIndex = vn.getAttrVal("sofa"); if (sofaAttrIndex > -1) n.setSofaXmiId(Integer.parseInt(vn.toRawString(sofaAttrIndex))); else n.setSofaXmiId(NO_SOFA_KEY); Map<String, List<Integer>> referencedXmiIds = getReferencedXmiIds(vn, n.getTypeName(), aCas.getTypeSystem()); n.setReferencedXmiIds(referencedXmiIds); referencedXmiIds.values().stream().flatMap(Collection::stream).map(refId -> nodesByXmiId.computeIfAbsent(refId, JeDISVTDGraphNode::new)).forEach(referenced -> referenced.addPredecessor(n)); if (n.getTypeName().equals(CAS_SOFA)) { nodesByXmiId.put(currentSecondSofaMapKey--, n); ((SofaVTDGraphNode) n).setSofaID(vn.toRawString(vn.getAttrVal("sofaID"))); } } } while (vn.toElement(VTDNav.NEXT_SIBLING)); return nodesByXmiId; }
String tableName = vn.toString(vn.getAttrVal("name")); String name = vn.toString(vn.getAttrVal("name"));
VTDGen vg = new VTDGen(); AutoPilot ap = new AutoPilot(); int i; ap.selectXPath("/root/element"); if (vg.parseFile(FILE_LOCATION,true)){ VTDNav vn = vg.getNav(); ap.bind(vn); // apply XPath to the VTDNav instance // AutoPilot moves the cursor for you while((i=ap.evalXPath())!=-1){ System.out.println("the attribute index val is "+ i +" the attribute string ==>"+vn.toString(vn.getAttrVal("attribute"))); } }
private boolean lang(VTDNav vn, String s){ // check the length of s boolean b = false; vn.push2(); try { while (vn.getCurrentDepth() >= 0) { int i = vn.getAttrVal("xml:lang"); if (i!=-1){ b = vn.matchTokenString(i,s); break; } vn.toElement(VTDNav.P); } } catch (NavException e) { } vn.pop2(); return b; } private boolean startsWith(VTDNav vn){
private boolean lang(VTDNav vn, String s){ // check the length of s boolean b = false; vn.push2(); try { while (vn.getCurrentDepth() >= 0) { int i = vn.getAttrVal("xml:lang"); if (i!=-1){ b = vn.matchTokenString(i,s); break; } vn.toElement(VTDNav.P); } } catch (NavException e) { } vn.pop2(); return b; } private boolean startsWith(VTDNav vn){
private boolean lang(VTDNav vn, String s){ // check the length of s boolean b = false; vn.push2(); try { while (vn.getCurrentDepth() >= 0) { int i = vn.getAttrVal("xml:lang"); if (i!=-1){ b = vn.matchTokenString(i,s); break; } vn.toElement(VTDNav.P); } } catch (NavException e) { } vn.pop2(); return b; } private boolean startsWith(VTDNav vn){
URL = null; if (URL == null) return getAttrVal(ln); int size = vtdBuffer.size; int index = (context[0] != 0) ? context[context[0]] + 1 : rootIndex + 1;
URL = null; if (URL == null) return getAttrVal(ln); int size = vtdBuffer.size; int index = (context[0] != 0) ? context[context[0]] + 1 : rootIndex + 1;
URL = null; if (URL == null) return getAttrVal(ln); int size = vtdBuffer.size; int index = (context[0] != 0) ? context[context[0]] + 1 : rootIndex + 1;
i++; if (vn.hasAttr("Owner")) System.out.println("Owner==>"+vn.toNormalizedString(vn.getAttrVal("Owner"))); System.out.println("Stats==>"+vn.toNormalizedString(vn.getAttrVal("Status"))); System.out.println("Version==>"+vn.toNormalizedString(vn.getAttrVal("Version"))); System.out.println("PMID==>"+vn.toNormalizedString(vn.getText())); VN.push(); while((ap3.evalXPath())!=-1){ System.out.println("PubModel==>"+vn.toNormalizedString(vn.getAttrVal("PubModel"))); VN.pop();
int i = vn.getAttrVal("attr"); if (i!=-1){ xm.updateToken(i,"value");
int nameIndexRef = navigateRef.getAttrVal("name"); String nameRef = navigateRef.toNormalizedString(nameIndexRef);