Dr said:
David Mark posted:
All elements of the document that have a SRC attribute.
HTML attribute names are declared and usually referred to all-lowercase.
AFAIR, that attribute is normally a string which looks like what one in
HTML writes between the quotes that follow 'a href=',
It is of type URI.
but always is in the full absolute form including protocol part.
No, it does not need to.
Those that are otherwise I do not want to find; but if they occur they can
be eliminated at a later stage.
That implies that in the end you cannot use properties of element objects,
but must refer to attributes of elements. There is a problem with this
approach as MSHTML does not always differentiate between those two kinds
(the well known IE getAttribute() bug).
They are not of concern, but illustrate by their collections what would
be a nice way to find all SRC elements.
The term "SRC elements" is wrong in this context. A "SRC element" would be
of the form <SRC …>, potentially followed by content and </SRC>.
Links, as in "`A' element", do not have a `src' attribute in HTML; they have
a `href' attribute instead.
No. I mean for finding all elements that have IDs; or rather, for
finding the ID values, as I do not need the element.
See < The corresponding XPath
expression would be
//*[(@src or @href) and @id]/@id
which can be refined to only include elements which `src' or `href'
attribute is of a certain form (to avoid filtering the results later).
For MSHTML you are on your own, though, and should use
getElementsByTagName(), as David suggested.
Another possibility would be querySelectorAll(), with which you can use CSS
selectors (in particular, CSS attribute selectors) to retrieve a NodeList
of elements. Be aware, though, that implementations vary due to varying
levels of CSS support in browser's layout engines, and that it is not
strictly defined if a CSS attribute selector applies to an element if the
element type has the attribute declared but not specified; implementations
differ there as well.
I don't want to have to know the tag names of all elements that can USE
an HTML SRC property.
HTML elements do not have properties. If you traverse the document tree
with the DOM, you do not have to know the tag names (better: element type
names) of all elements that have a `src' _attribute_; elements that do not
have it, usually do not expose the corresponding attribute property for
their element objects. As a result, a `typeof' test should suffice.
And, surely, one can apply a SRC property to any element by script?
Not necessarily. And AISB, doing so is strongly recommended against.
I am trying to find all SRC attribute values in the document that name
required files, and prepared to receive any that do not refer to files
(Throughout, the files can be present or absent)
//*[@src]/@src
Evidently.
Which might have to do with your not expressing yourself in an
understandable manner, inventing terminology where unambiguous standard
terminology exists already.
All the ones of interest are strings; it should suffice to use typeof
and note non-strings for future consideration.
So you already know that. Why ask the question, then?
But the best answer is the one which appeared immediately after my
article "above" was committed to NNTP.
Are you sure?
The tree-walk which recursively locates all IDs was recently added to the
code, and slows it by an unimportant amount.
IMHO, it is still a kludge compared to the approach using W3C DOM Level 3
XPath, which is available in all major DOMs (regardless of Content-Type)
except the MSHTML DOM. You really only need it for IE and older versions of
other UAs nowadays.
It will therefore be, and is, entirely satisfactory and efficient to test
elements for having a SRC during the same tree-walk.
Well, YMMV.
PointedEars