HTML file: add annotations through IHTMLDocument

Posted by peterchen on Stack Overflow See other posts from Stack Overflow or by peterchen
Published on 2010-04-14T10:11:44Z Indexed on 2010/04/14 10:13 UTC
Read the original article Hit count: 290

Filed under:
|
|
|

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.

© Stack Overflow or respective owner

Related posts about c++

Related posts about win32