VTD-XML -- XPath Evaluation Performance

1 view (last 30 days)
Konstantinos Sofos
Konstantinos Sofos on 3 Jul 2014
Answered: Koen on 14 Nov 2014
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

Answers (1)

Koen
Koen on 14 Nov 2014
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

Community Treasure Hunt

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

Start Hunting!