How do I obtain marked content ID for an element on a PDF page?

Q: I am attempting to determine the object ID as seen in COS edit of
an element as I read them.

Dim reader As ElementReader = New ElementReader
Dim element As Element

For i As Integer = 1 To pDoc.GetPageCount()
Dim page As Page = pDoc.GetPage(1)

reader.Begin(page)

Dim new_page As Page = pDoc.PageCreate()
pDoc.PagePushBack(new_page)
writer.Begin(new_page)

element = reader.Next()
While (Not IsNothing(element))
  'code to access element methods here
Loop
Next

I am able to obtain the object ID of the elements using SElement as in
the LogicalStructure sample code, but how do I tie SElement to
Element, I need the ID of Element so I can replace text by element
ID. Is there a better way of replacing text by element ID (referring
to object ID as in cos edit).

Thanks any help greatly appreciated.
------
A: 'Elements' within page content streams do not have a COS (SDF)
object number. You could use a counter to enumerate and assign an id
to each element, but the elements themselves are not stored within
xref table in PDF. You could obtain the object number for the stream
which holds all elements using page.GetSDFObj().GetObjNum().

If you would like to obtain the marked content ID to relate a page
Element to a structure element (pdftron.PDF.Struct.SElement) you could
use element.GetStructMCID(). This method will return marked content ID
(mcid) for a given element. The 'mcid' can be used to search for
corresponding element in the structure tree, or the other way around
from structure element to page content. As a starting point, you may
want to take a look at third example in LogicalStructure sample
(http://www.pdftron.com/net/samplecode.html#LogicalStructure).