Talk:XPath: Difference between revisions

From MozillaZine Knowledge Base
Jump to navigationJump to search
mNo edit summary
No edit summary
Line 11: Line 11:


::HTML is not XML but HTML has a DOM and XPath works with HTML [[User:Jgraham|Jgraham]]
::HTML is not XML but HTML has a DOM and XPath works with HTML [[User:Jgraham|Jgraham]]
:::I think you are confusing the [http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html Document Object Model Core] specification with the [http://www.w3.org/TR/DOM-Level-2-HTML/html.html Document Object Model HTML] specification. The former defines interfaces such as Document, Node, Element, Attr, etc., while the latter defines interfaces such as HTMLDocument and HTMLElement. The [http://www.w3.org/TR/2004/NOTE-DOM-Level-3-XPath-20040226/xpath.html Document Object Model XPath], which defines interfaces such as XPathEvaluator, XPathExpression, and XPathResult (some of which are used in this article's evaluateXPath() function), maps the DOM Core specification and the [http://www.w3.org/TR/xpath XPath] specification , but <b>not</b> DOM HTML and XPath. Indeed, if you try to use any of the methods in the DOM XPath interfaces (e.g., <code>XPathEvaluator.evaluate()</code>) with DOM HTML interfaces, you will get an exception. Try it if you don't believe me. [[User:Grimholtz|grimholtz]]

Revision as of 06:25, 30 March 2005

asquella, why did you write 'Note that you shouldn't use this function if you expect to get a long list of results from it.' --grimholtz

That function copies query results to an array, taking additional memory and CPU cycles. I wouldn't use it at all, but for simple queries I think that simpler interface is worth the overhead. (Not that I've done any profiling.)
Related example (though not completely applicable): try opening JS Console when it has a lot of entries asqueella


So this page is actually a bit misleading in that it suggests that you can only use XPath with XML - infact it will work with any DOM tree. I'm also not sure that making use of a helper function actually helps people understand what's going on (but then I should finish my documentation...) --Jgraham 03:20, 20 Mar 2005 (PST)

DOM trees are in-memory representations of XML. They are one and the same, so I don't see how this can be misleading.
HTML is not XML but HTML has a DOM and XPath works with HTML Jgraham
I think you are confusing the Document Object Model Core specification with the Document Object Model HTML specification. The former defines interfaces such as Document, Node, Element, Attr, etc., while the latter defines interfaces such as HTMLDocument and HTMLElement. The Document Object Model XPath, which defines interfaces such as XPathEvaluator, XPathExpression, and XPathResult (some of which are used in this article's evaluateXPath() function), maps the DOM Core specification and the XPath specification , but not DOM HTML and XPath. Indeed, if you try to use any of the methods in the DOM XPath interfaces (e.g., XPathEvaluator.evaluate()) with DOM HTML interfaces, you will get an exception. Try it if you don't believe me. grimholtz