javascript - Which is faster, XPath or Regexp? -


I am creating an add-on for Firefox and it loads an html page using Ajax (add-ons) In it is the XUL panel).

Now at this point, I was not looking for ways to create a document object and to keep Ajax request contents in it, and then what do I need using the xpath . Instead I am loading content and parsing it as text with regular dissemination.

But I got a question which would be better to use, xPath or regular expression? Which fast performance?

The HTML page contains hundreds of elements that contain the same text, and what I want to do is count how many elements exist.

I want to add my add-on as soon as possible and I do not know the mechanics behind the regxp or xpath, so I do not know which is more effective.

Hope I was clear. Thanksgiving

Whenever you are working with XML, XPath (or XSLT, XQuery, SAX, DOM or any other) other XML-aware method to go through your data).

Why? XML processing is complex and dealing with all its incompatibilities, external / pars / unparsing institutions, DTD, processing instructions, whitespace handling, colding, unicode normalization, CDATA section etc, to make it a reliable rebirth lot Think of the way to get your data, think that it has learned the years of industry how to parse XML best, This should be reason enough Do not try to do it yourself .

Answer your question: When it comes to speed (which not should be your primary concern), it relies heavily on the implementation of XPath or Regex compiler / processor Occasionally, XPath will be fast (i.e., if possible, or possibly compiled XSLT), second time, regexes will be faster (if you can use precompold regex and your query is easy). But compared to HELM / XML, Regedx is not easy, because there is nested bracket (tags) problem, which can not be solved with Reggaeus alone.

If the input is too large, then regex is faster, as long as the XPath implementation can be streaming processing (which I believe is not the method inside Firefox).

You have written: / P>

"Which is more effective" *

He makes you quick for a reliable and stable implementation Use XPath which is comparatively fast. It is used within Firefox and other browsers, as well as if you need your code to run from the browser.


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -