VTD-XML -- XPath Evaluation Performance

조회 수: 3 (최근 30일)
Konstantinos Sofos
Konstantinos Sofos 2014년 7월 3일
답변: Koen 2014년 11월 14일
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