I have the following DOM structure. My application has to make repeated
requests to find the Label element value for each Patch element in a Side
element. I may have up to 2000 Patches per Side. All my application knows
is the Side Index and the RowIndex & ColIndex. Because these are
attributes, I am getting a list of Patch elements and then for each Patch, I
get the list of attributes and then I read each attribute value to see if it
matches the one I am looking for.
Needless to say, this is in-efficient. My requests take quite a long time
on a fast PC. I am wondering if I either have bad search code(see below) or
should I not store the data this way? I have control over both. It seems
it would be faster to search if I changed the Patch element name to contain
the RowIndex and ColIndex, such as Patch_Row#_Col#.
Can anyone give me some insight into the best way of handling this problem?
<Side Index="0">
<NumRows>21</NumRows>
<NumCols>55</NumCols>
<Patch RowIndex="20" ColIndex="0">
<Label>1101</Label>
</Patch>
<Patch RowIndex="20" ColIndex="1">
<Label>1102</Label>
</Patch>
<Patch RowIndex="20" ColIndex="2">
<Label>1103</Label>
</Patch>
...lots more Patch elements...
</Side>
<Side Index="1">
<NumRows>21</NumRows>
<NumCols>55</NumCols>
<Patch RowIndex="20" ColIndex="0">
<Label>1101</Label>
</Patch>
<Patch RowIndex="20" ColIndex="1">
<Label>1102</Label>
</Patch>
<Patch RowIndex="20" ColIndex="2">
<Label>1103</Label>
</Patch>
...lots more Patch elements...
</Side>
...lots more Side elements...
Code...
DOMNode* CTarget::GetPatchNode(DOMNode* pSideNode, int iRowIndex, int
iColIndex)
{
DOMNodeList* pPatchNodeList =
((DOMElement*)pSideNode)->getElementsByTagNameNS(NULL, L"Patch");
if (pPatchNodeList)
{
int iNumPatchNodes = pPatchNodeList->getLength();
for (XMLSize_t p=0; p<iNumPatchNodes; p++)
{
DOMNode* pPatchNode = pPatchNodeList->item(p);
if (pPatchNode)
{
bool bRowFound = false;
bool bColFound = false;
DOMNamedNodeMap* pDOMNamedNodeMap =
pPatchNode->getAttributes();
int iNumAttributes = pDOMNamedNodeMap->getLength();
for (XMLSize_t a=0; a<iNumAttributes; a++)
{
DOMNode* pDOMNode = pDOMNamedNodeMap->item(a);
if (pDOMNode)
{
const XMLCh* pwszNodeName =
pDOMNode->getNodeName();
if (wcscmp(L"ColIndex", pwszNodeName)
== 0)
{
const XMLCh* wszNodeValue =
pDOMNode->getNodeValue();
ASSERT(wszNodeValue);
if (_ttoi(wszNodeValue) ==
iColIndex)
bColFound = true;
else
break;
}
if (wcscmp(L"RowIndex", pwszNodeName)
== 0)
{
const XMLCh* wszNodeValue =
pDOMNode->getNodeValue();
ASSERT(wszNodeValue);
if (_ttoi(wszNodeValue) ==
iRowIndex)
bRowFound = true;
else
break;
}
if (bRowFound && bColFound)
return pPatchNode;
}
}
}
}
}
return NULL;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]