selectElementNS() public method

Select the element name (name space version) before iterating. URL, if set to *, matches every namespace URL, if set to null, indicates the namespace is undefined. localname, if set to *, matches any localname Creation date: (12/4/03 6:05:19 PM)
public selectElementNS ( System ns_URL, System ln ) : void
ns_URL System
ln System java.lang.String ///
return void
Ejemplo n.º 1
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("./servers.xml", true))
         {
             VTDNav vn = vg.getNav();
             AutoPilot ap = new AutoPilot(vn);
             ap.selectElementNS("http://purl.org/dc/elements/1.1/", "*"); // select name space here; * matches any local name
             int count = 0;
             while (ap.iterate())
             {
                 Console.Write("" + vn.getCurrentIndex() + "  ");
                 Console.WriteLine("Element name ==> " + vn.toString(vn.getCurrentIndex()));
                 int t = vn.getText(); // get the index of the text (char data or CDATA)
                 if (t != -1)
                     Console.WriteLine(" Text  ==> " + vn.toNormalizedString(t));
                 Console.WriteLine("\n ============================== ");
                 count++;
             }
             Console.WriteLine("Total # of element " + count);
         }
     }
     catch (NavException e)
     {
         Console.WriteLine(" Exception during navigation " + e);
     }
 }
Ejemplo n.º 2
0
		public int computeContextSize(Predicate p, VTDNav vn){
	    
	    bool b = false;
	    Predicate tp = null;
	    int i = 0;
	    AutoPilot ap;
	    switch(currentStep.axis_type){
	    	case AxisType.CHILD:
	    	    if (currentStep.nt.testType != NodeTest.TEXT){
	    	    b = vn.toElement(VTDNav.FIRST_CHILD);
	    		if (b) {
	    		    do {
	    		        if (currentStep.eval(vn, p)) {
                        	i++;
	    		        }
	    		    } while (vn.toElement(VTDNav.NS));	    		    
	    		    vn.toElement(VTDNav.PARENT);
	    		    currentStep.resetP(vn,p);
	    		    return i;
	    		} else
	    		    return 0;
	    	    }else {	    
	    	        TextIter ti = new TextIter();
	    	        ti.touch(vn);
	    	        while((ti.getNext())!=-1){
	    	            if (currentStep.evalPredicates(vn,p)){
	    	                i++;
	    	            }
	    	        }
	    	        currentStep.resetP(vn,p);
	    	        return i;
	    	    }
	    		   
			case AxisType.DESCENDANT_OR_SELF:
			case AxisType.DESCENDANT:
			case AxisType.PRECEDING:								
			case AxisType.FOLLOWING:
			    
			    String helper = null;
				if (currentStep.nt.testType == NodeTest.NODE){
				    helper = "*";
				}else {
				    helper = currentStep.nt.nodeName;
				}
				ap = new AutoPilot(vn);
				if (currentStep.axis_type == AxisType.DESCENDANT_OR_SELF )
					if (currentStep.nt.testType == NodeTest.NODE)
                        ap.Special = true;
					else
						ap.Special = false;
				//currentStep.o = ap = new AutoPilot(vn);
			    if (currentStep.axis_type == AxisType.DESCENDANT_OR_SELF)
			        if (currentStep.nt.localName!=null)
			            ap.selectElementNS(currentStep.nt.URL,currentStep.nt.localName);
			        else 
			            ap.selectElement(helper);
				else if (currentStep.axis_type == AxisType.DESCENDANT)
				    if (currentStep.nt.localName!=null)
				        ap.selectElementNS_D(currentStep.nt.URL,currentStep.nt.localName);
				    else 
				        ap.selectElement_D(helper);
				else if (currentStep.axis_type == AxisType.PRECEDING)
				    if (currentStep.nt.localName!=null)
				        ap.selectElementNS_P(currentStep.nt.URL,currentStep.nt.localName);
				    else 
				        ap.selectElement_P(helper);
				else 
				    if (currentStep.nt.localName!=null)
				        ap.selectElementNS_F(currentStep.nt.URL,currentStep.nt.localName);
				    else 
				        ap.selectElement_F(helper);
			    vn.push2();
    			while(ap.iterate()){
    				if (currentStep.evalPredicates(vn,p)){
    					i++;
    				}
    			}
    			vn.pop2();
    			currentStep.resetP(vn,p);
    			return i;
			  
			case AxisType.PARENT:
			    vn.push2();
				i = 0;
				if (vn.toElement(VTDNav.PARENT)){
				    if (currentStep.eval(vn,p)){
				        i++;
				    }
				}			    
				vn.pop2();
				currentStep.resetP(vn,p);
				return i;
				
			case AxisType.ANCESTOR:
			    vn.push2();
				i = 0;
				while (vn.toElement(VTDNav.PARENT)) {
				    if (currentStep.eval(vn, p)) {
                    	i++;
    		        }
				}				
				vn.pop2();
				currentStep.resetP(vn,p);
				return i;
				
			case AxisType.ANCESTOR_OR_SELF:
			    vn.push2();
				i = 0;
				do {
				    if (currentStep.eval(vn, p)) {
                    	i++;
    		        }
				}while(vn.toElement(VTDNav.PARENT));
				vn.pop2();
				currentStep.resetP(vn,p);
				return i;
				
			case AxisType.SELF:
			    i = 0;
				if (vn.toElement(VTDNav.PARENT)){
				    if (currentStep.eval(vn,p)){
				        i++;
				    }
				}			    
				currentStep.resetP(vn,p);
				return i;
			    
			case AxisType.FOLLOWING_SIBLING:
			    vn.push2();
				while(vn.toElement(VTDNav.NEXT_SIBLING)){
				    if (currentStep.eval(vn,p)){
				        i++;
				    }
				}			    
			    vn.pop2();
				currentStep.resetP(vn,p);
				return i;
			    
			case AxisType.PRECEDING_SIBLING:
			    vn.push2();
				while(vn.toElement(VTDNav.PREV_SIBLING)){
				    if (currentStep.eval(vn,p)){
				        i++;
				    }
				}			    
				vn.pop2();
				currentStep.resetP(vn,p);
				return i;
				
			case AxisType.ATTRIBUTE:
			    ap = new AutoPilot(vn);
				if (currentStep.nt.localName!=null)
				    ap.selectAttrNS(currentStep.nt.URL,
			            currentStep.nt.localName);
				else 
				    ap.selectAttr(currentStep.nt.nodeName);
				i = 0;
				while(ap.iterateAttr()!=-1){
				    if (currentStep.evalPredicates(vn,p)){
				        i++;
				    }
				}
          		currentStep.resetP(vn,p);
				return i;
			    
	    	default:
	    	    throw new XPathEvalException("axis not supported");
	    }
	    //return 8;
	}