VTD-XML -- XPath Evaluation Performance

3 次查看(过去 30 天)
For a lot of years i use DOM oblects (JDK) to read XML files (XPath). Since some weeks i found the * VTD-XML * and i would like to ask if anyone has arleady use it, if yes how and what is your opinion. Thanks in advance.
classdef XPath
% xpath.XPath Class for using xpath on Java DOM objects
%
% This class is a small wrapper for the XPATH functionality packaged
% in javax.xml.parsers.* and javax.xml.xpath.*
%
properties
domFactory
builder
doc
factory
xpath
end
methods
function this = XPath( xmlFile )
% XPath Constructor
%
% The constructor only takes one argument, an xml file.
% It returns a handle to the object created.
import javax.xml.parsers.*;
import javax.xml.xpath.*;
this.domFactory = DocumentBuilderFactory.newInstance();
this.builder = this.domFactory.newDocumentBuilder();
this.doc = this.builder.parse(xmlFile);
this.factory = XPathFactory.newInstance();
this.xpath = this.factory.newXPath();
end
function result = evaluateExpression( this, expressionStr )
% evaluateExpression Evaluate XPATH expression on doc object
%
% This is the general function, which will perform an xpath
% search on the top level object.
%
% See also xpath.XPath/setBaseDoc
import javax.xml.xpath.*;
expression = this.xpath.compile(expressionStr);
result = expression.evaluate(this.doc, XPathConstants.NODESET);
end
function result = evaluateExpressionInElem( this, expressionStr, elem )
import javax.xml.xpath.*;
expression = this.xpath.compile(expressionStr);
result = expression.evaluate(elem, XPathConstants.NODESET);
end
function newDoc = setBaseDoc( this, expressionStr )
% setBaseDoc Change what the doc attribute points to
elem = evaluateExpression( this, expressionStr );
if ~isempty( elem ) && elem.getLength==1
this.doc = elem.item(0);
end
if nargout > 0
newDoc = this.doc;
end
end
end
end

回答(1 个)

Koen
Koen 2014-11-14
Amigo,
Did you already solved it? I figured that you can use VTD-XML in matlab. it is possible and i did it on my internship.
I'm not experienced with java or matlab. So you can do it too.
greets,
Koen

类别

Help CenterFile Exchange 中查找有关 Structured Data and XML Documents 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by