Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    XMLTools.selectNodes() problem

    I am hitting a website that supports xml downloads.

    here is a smple link:

    Code:
    var url = http://clinicaltrials.gov/search?intr=Cetuximab&displayxml=true
    XMLTools.loadXML(url, "ctTool.parseXML(xmlDoc, xmlText)");
    I process this in the following method:

    Code:
    parseXML: function(xmlDoc, xmlText) {
        	if (xmlDoc == null) {
        		return;
        	}
        	var studies = XMLTools.selectNodes(xmlDoc, "//clinical_study");
        	Log.logInfo("Number of studies found: " + studies.length);
        	var trialList = [];
        	for (var i = 0; i < studies.length; i++) {
        		var study = studies[i];
        		var trial = new Object();
        		Log.logInfo("found study: " + XMLTools.selectString(study, "//nct_id"));
        		trial.NCTID = XMLTools.selectString(study, "//nct_id");
        		trial.title = XMLTools.selectString(study, "//title");
        		trial.url = XMLTools.selectString(study, "//url");
        		trialList[trialList.length] = trial;
        	}
    }
    The loop seems to get stuck on the first element. I get a count of 20 "clinical_trial" elements back in the xmlDoc (which is correct) but in the Log.logInfo() I get the first study back 20 times.

    Thoughts?
    -pf

    #2
    In XPath, "//" is always document-relative, even if executed in the scope of a specific node. You want ".//" to search under the target node.

    Comment

    Working...
    X