Find all elements in a page with the given tag name and/or attribute and value.
| Return Type | Function name | Arguments |
|---|---|---|
| hzEcode | hzDocHtml::FindElements | (hzVect<hzHtmElem*>&,hzString&,hzString&,hzString&,) |
Declared in file: hzDocument.h
Defined in file : hzDocHtml.cpp
Function Logic:
Function body:
hzEcode hzDocHtml::FindElements (hzVect<hzHtmElem*>& elements)hzString& htag, hzString& attrName, hzString& attrValue,
{
// Find all elements in a page with the given tag name and/or attribute and value.
//
// Arguments: 1) elements Elements found in order of incidence in this document matching on tag type and on attribute name and value if supplied.
// 2) htag The tag type. This is compulsory and matches only elements of the given type.
// 3) aname The attribute name. This is optional but if supplied, will require elements to have an attribute of the supplied name
// 4) avalue The attribute value. Also optional but if supplied, will require elements to have an attribute of the supplied name
//
// Returns: E_NOTFOUND If no elements matched
// E_OK If elements matched
hzHtmElem* pElement ; // HTML node
hzAttrset ai ; // Attribute iterator
hzString anam ; // Attribute name
hzString aval ; // Attribute value
hzString S ; // Content of link node
hzUrl link ; // URL of link
uint32_t Lo ; // First element in m_mapTags to investigate
uint32_t Hi ; // Last element in m_mapTags to investigate
uint32_t nIndex ; // Links iterator
bool bOk ; // OK to insert the element
elements.Clear() ;
Lo = 0;
Hi = m_mapTags.Count() - 1;
if (htag)
{
// A tagname has been supplied so limit the investigation to tags with the tagname
Lo = m_mapTags.First(htag) ;
if (Lo < 0)
return E_NOTFOUND ;
Hi = m_mapTags.Last(htag) ;
}
// Investigate elements
for (nIndex = Lo ; nIndex <&eq; Hi ; nIndex++)
{
pElement = m_mapTags.GetObj(nIndex) ;
bOk = false ;
if (attrName)
{
// An attrubute name has been supplied so the element must have this attribute
for (ai = pElement ; ai.Valid() ; ai.Advance())
{
anam = ai.Name() ; aval = ai.Value() ;
if (anam == attrName)
{
if (!attrValue)
bOk = true ;
else
{
if (aval == attrValue)
bOk = true ;
}
}
}
}
else
{
if (attrValue)
{
// An attribute value ...
for (ai = pElement ; ai.Valid() ; ai.Advance())
{
anam = ai.Name() ; aval = ai.Value() ;
if (aval == attrValue)
bOk = true ;
}
}
}
if (bOk)
// elements.Insert(pElement) ;
elements.Add(pElement) ;
}
return E_OK ;
}