xpath nodeset中有多少个元素

时间:2011-10-18 11:07:39

标签: java dom matlab xpath

我有这个matlab功能:

function trackName = getTrackName(xpath, gpxSourceDom)
    % Import the XPath classes
    import javax.xml.xpath.*

    % Compile the expression
    expression = xpath.compile('gpx/trk/name');

    % Apply the expression to the DOM.
    trackNames = expression.evaluate(gpxSourceDom, XPathConstants.NODESET);
end

我需要一种方法来打印trackNames NODESET中的每个元素。我怎么能这样做?

1 个答案:

答案 0 :(得分:0)

快速搜索MATLAB和xpath会返回以下结果: using xpath in matlab

您缺少的部分是遍历结果并显示名称。有关节点的更多信息,请查看javadoc

for i = 1:nodeList.getLength node = nodeList.item(i-1); disp(char(node.getFirstChild.getNodeValue)) end