HTML file: add annotations through IHTMLDocument
- by peterchen
I need to add "annotations" to existing HTML documents - best in the form of string property values I can read & write by name.
Apparently (to me), meta elements in the header seem to be the common way - i.e. adding/modifying elements like
<head>
<meta name="unique-id_property-name" content="property-value"/>
...
</head>
Question 1: Ist that "acceptable" / ok, or is there a better way to add meta data?
I have a little previous experience with getting/mut(il)ating HTML contents through the document in an web browser control. For this task, I've already loaded the HTML document into a HTMLDocument object, but I'm not sure how to go on:
// what I have
IHTMLDocument2Ptr doc;
doc.CreateInstance(__uuidof(HTMLDocument));
IPersistFile pf = doc;
pf->Load(fileName, STGM_READ);
// everything ok until here
Questions 2: Should I be using anything else than HTMLDocument?
Questions 3..N:
How do I get the head element?
How do I get the value of a meta element with a given name?
How do I set the value of a meta element (adding the item if and only if it doesn't exist yet)?
doc->all returns a collection of all tags, which I can enumerate even though count returns 0. I could scan that for head, then scan that for all meta where the name starts with a certain string, etc. - but this feels very clumsy.