nrg_alpha wrote:Then it donned on me, is this access to the <a> tag nested within the div tag?
XPath. "//" is an abbreviation for "/descendant-or-self::node()/" - the current node and all of its descendants - the entire subtree from that point down. Since the path started with '/', the current node is the document root, and therefore starting with '//' nets you every node in the entire document.
"*" represents all element children of the current node(s) - as opposed to children that are attributes, text, comment, and whatnot. It's really only there because I needed something to hang the predicate off of.
"a" is short for "child::a" - children of the current node(s) that are <a> elements.
I'm not sure what's going on with the item(0) business...
DomXPath::query() returns a DomNodeList, and I'm just interested in the item at the head of the list, that's item(0). I don't want the <a> element itself, only its text content.
What gets me is $dom->getElementById('Colour') doesn't work because there's no inherent mapping between the attribute named "id", and the id type. Even if you specify loading the document as HTML.
You can specify which attribute is the ID by using setIdAttribute on the element, but to do that you have to already have the element – so you no longer need to get it, by ID or otherwise.