本文整理汇总了C++中HtmlElement::NameIs方法的典型用法代码示例。如果您正苦于以下问题:C++ HtmlElement::NameIs方法的具体用法?C++ HtmlElement::NameIs怎么用?C++ HtmlElement::NameIs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HtmlElement
的用法示例。
在下文中一共展示了HtmlElement::NameIs方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: utassert
static void HtmlParser02()
{
HtmlParser p;
HtmlElement *root = p.Parse("<a><b/><c></c ><d at1=\"<quo&ted>\" at2='also quoted' att3=notquoted att4=end/></a>");
utassert(4 == p.ElementsCount());
utassert(4 == p.TotalAttrCount());
utassert(root->NameIs("a"));
utassert(NULL == root->next);
HtmlElement *el = root->down;
utassert(el->NameIs("b"));
utassert(root == el->up);
el = el->next;
utassert(el->NameIs("c"));
utassert(root == el->up);
el = el->next;
utassert(el->NameIs("d"));
utassert(NULL == el->next);
utassert(root == el->up);
ScopedMem<WCHAR> val(el->GetAttribute("at1"));
utassert(str::Eq(val, L"<quo&ted>"));
val.Set(el->GetAttribute("at2"));
utassert(str::Eq(val, L"also quoted"));
val.Set(el->GetAttribute("att3"));
utassert(str::Eq(val, L"notquoted"));
val.Set(el->GetAttribute("att4"));
utassert(str::Eq(val, L"end"));
}
示例2:
HtmlElement *HtmlParser::FindParent(char *tagName)
{
if (str::Eq(tagName, "li")) {
// make a list item the child of the closest list
for (HtmlElement *el = currElement; el; el = el->up) {
if (el->NameIs("ul") || el->NameIs("ol"))
return el;
}
}
return currElement;
}
示例3: while
HtmlElement *HtmlParser::FindElementByNameNS(const char *name, const char *ns, HtmlElement *from)
{
HtmlElement *el = from ? from : rootElement;
if (from)
goto FindNext;
if (!el)
return NULL;
CheckNext:
if (el->NameIs(name) || ns && el->NameIsNS(name, ns))
return el;
FindNext:
if (el->down) {
el = el->down;
goto CheckNext;
}
if (el->next) {
el = el->next;
goto CheckNext;
}
// backup in the tree
HtmlElement *parent = el->up;
while (parent) {
if (parent->next) {
el = parent->next;
goto CheckNext;
}
parent = parent->up;
}
return NULL;
}
示例4: HtmlParserFile
static void HtmlParserFile()
{
WCHAR *fileName = L"HtmlParseTest00.html";
// We assume we're being run from obj-[dbg|rel], so the test
// files are in ..\src\utils directory relative to exe's dir
ScopedMem<WCHAR> exePath(GetExePath());
const WCHAR *exeDir = path::GetBaseName(exePath);
ScopedMem<WCHAR> p1(path::Join(exeDir, L"..\\src\\utils"));
ScopedMem<WCHAR> p2(path::Join(p1, fileName));
char *d = file::ReadAll(p2, NULL);
// it's ok if we fail - we assume we were not run from the
// right location
if (!d)
return;
HtmlParser p;
HtmlElement *root = p.ParseInPlace(d);
utassert(root);
utassert(709 == p.ElementsCount());
utassert(955 == p.TotalAttrCount());
utassert(root->NameIs("html"));
HtmlElement *el = root->down;
utassert(el->NameIs("head"));
el = el->next;
utassert(el->NameIs("body"));
el = el->down;
utassert(el->NameIs("object"));
el = el->next;
utassert(el->NameIs("ul"));
el = el->down;
utassert(el->NameIs("li"));
el = el->down;
utassert(el->NameIs("object"));
ScopedMem<WCHAR> val(el->GetAttribute("type"));
utassert(str::Eq(val, L"text/sitemap"));
el = el->down;
utassert(el->NameIs("param"));
utassert(!el->down);
utassert(el->next->NameIs("param"));
el = p.FindElementByName("body");
utassert(el);
el = p.FindElementByName("ul", el);
utassert(el);
int count = 0;
while (el) {
++count;
el = p.FindElementByName("ul", el);
}
utassert(18 == count);
free(d);
}
示例5: CloseTag
void HtmlParser::CloseTag(char *tagName)
{
str::ToLower(tagName);
// to allow for lack of closing tags, e.g. in case like
// <a><b><c></a>, we look for the first parent with matching name
for (HtmlElement *el = currElement; el; el = el->up) {
if (el->NameIs(tagName)) {
currElement = el->up;
return;
}
}
// ignore the unexpected closing tag
}
示例6: CloseTag
void HtmlParser::CloseTag(HtmlToken *tok)
{
char *tagName = NULL;
if (Tag_NotFound == tok->tag) {
tagName = (char *)tok->s;
char *tagEnd = tagName + tok->nLen;
*tagEnd = '\0';
}
// to allow for lack of closing tags, e.g. in case like
// <a><b><c></a>, we look for the first parent with matching name
for (HtmlElement *el = currElement; el; el = el->up) {
if (tagName ? el->NameIs(tagName) : tok->tag == el->tag) {
currElement = el->up;
return;
}
}
// ignore the unexpected closing tag
}