From the current node (the node used to call this member function), find all sub-nodes matching the supplied criteria. The critieria will be that required to uniquely identify a tag and optionally that required to specify a tag attribute and optionally that required to specify a value for the tag or attribute. The convention is to use the :: symbol between tag levels where these are needed and the -> symbol to name the tag attribute and the = symbol to specify a value. Criteria can thus be of the forms:- 1) tagname 2) level0tagname...levelNtagname 3) ....tagname="some value" 4) ....tagname->attribute 5) ....tagname->attribute="some value" The criteria must only serve to identify a single tag or tag attribute. All nodes matching matching this criteria are then compiled into the supplied hzVect. Note that only the nodes will be placed in the vector and not the attributes. The application will have to use the hzXmlNode member fuctions for accessing attributes and there values if these are required. Pointer to subnode matching supplied criteria NULL If no subnode matches
| Return Type | Function name | Arguments |
|---|---|---|
| hzXmlNode* | hzXmlNode::FindSubnode | (const char*,) |
Declared in file: hzDocument.h
Defined in file : hzDocXml.cpp
Function Logic:
Function body:
hzXmlNode* hzXmlNode::FindSubnode (const char* srchExp)
{
// From the current node (the node used to call this member function), find all sub-nodes matching the supplied criteria.
//
// The critieria will be that required to uniquely identify a tag and optionally that required to specify a tag attribute and optionally that
// required to specify a value for the tag or attribute. The convention is to use the :: symbol between tag levels where these are needed and
// the -> symbol to name the tag attribute and the = symbol to specify a value. Criteria can thus be of the forms:-
//
// 1) tagname
// 2) level0tagname...levelNtagname
// 3) ....tagname="some value"
// 4) ....tagname->attribute
// 5) ....tagname->attribute="some value"
//
// The criteria must only serve to identify a single tag or tag attribute. All nodes matching matching this criteria are then compiled into the
// supplied hzVect. Note that only the nodes will be placed in the vector and not the attributes. The application will have to use the hzXmlNode
// member fuctions for accessing attributes and there values if these are required.
//
// Arguments: 1) srchExp The search expression that decendent nodes of this node, must match to be included in the result
//
// Returns: Pointer to subnode matching supplied criteria
// NULL If no subnode matches
hzXmlNode* pResult ; // Node pointer
char* cpBuf ; // Buffer for breaking up criteria
const char* i ; // Char iterator
const char* x ; // Char iterator
char* j ; // Buffer populator
hzString tagname ; // The part of the criteria needed to name the tag
hzString attrname ; // The part of the criteria needed to name the tag attribute
hzString value ; // The part of the criteria needed to specify node or node attribute values
bool bMatch ; // Node has passed criteria
/*
** ** Create a temp buffer
** */
cpBuf = new char[strlen(srchExp) + 1];
/*
** ** We first check for criteria of the form tagname.tagname .....
** ** If we do have this we have to recurse this function
** */
x = strchr(srchExp, CHAR_PERIOD) ;
if (x)
{
i = srchExp ;
j = cpBuf ;
for (; *i && *i != CHAR_PERIOD ;)
*j++ = *i++ ;
*j = 0;
tagname = cpBuf ;
pResult = _findsubnode(bMatch, tagname, attrname, value) ;
delete cpBuf ;
if (pResult && bMatch)
return pResult->FindSubnode(x + 1);
return 0;
}
/*
** ** Objain the tagname, any attribute name and value from the criteria
** */
i = srchExp ;
j = cpBuf ;
for (; *i ; i++)
{
if (*i == CHAR_EQUAL || (*i == ''-''&&i[1]== ''>''))
break ;
*j++ = *i ;
}
*j = 0;
tagname = j = cpBuf ;
if (i[0]== ''-''&&i[1]== ''>'')
{
for (i += 2; *i ; i++)
{
if (*i == CHAR_EQUAL)
break ;
*j++ = *i ;
}
*j = 0;
attrname = j = cpBuf ;
}
if (*i == CHAR_EQUAL)
{
for (i++ ; *i && *i != CHAR_SQUOTE ; i++) ;
for (i++ ; *i ; i++)
{
if (*i == CHAR_SQUOTE)
break ;
*j++ = *i ;
}
*j = 0;
value = cpBuf ;
}
delete cpBuf ;
/*
** ** Find the subnode by recursive search
** */
pResult = _findsubnode(bMatch, tagname, attrname, value) ;
if (pResult && bMatch)
return pResult ;
return 0;
}