If you aren't going to actually need the tree structure, use the SAX
interface instead and just pull the elements out as you see them, and store
the ones you want in your own data structures. It'll probably be far faster.

-------------------------------------
Dean Roddey
The Charmed Quark Controller
[EMAIL PROTECTED]
www.charmedquark.com
 


-----Original Message-----
From: David Hoffer [mailto:[EMAIL PROTECTED] 
Sent: Sunday, September 14, 2003 3:06 PM
To: [EMAIL PROTECTED]
Subject: DOM performance/coding issue


I have a question about how to effectively parser a large DOM document.  For
example, I have a lot of 'PatchData' elements.  I am looking for the set of
these where the child element 'CbName' matches a certain string.  The
following code takes 30 seconds just to loop through the DOMNodeList before
it finds the first matching child.  How can I make this faster?

DOMNodeList* pDOMNodeList =
m_pDocument->getDocumentElement()->getElementsByTagNameNS(NULL,
L"PatchData");

for (int i=0; i<pDOMNodeList->getLength(); i++)
{
        DOMNode* pDOMNode = pDOMNodeList->item(i);
        DOMNodeList* pDOMNodeList = ((const
DOMElement*)pDOMNode)->getElementsByTagNameNS(NULL, L"CbName");
        pDOMNode = pDOMNodeList->item(0);
        DOMNode* pChildNode = pDOMNode->getFirstChild();
        std::wstring wstrTagValue = pChildNode->getNodeValue();

        if (wcscmp(wstrTagValue.c_str(), m_wstrColorbarName.c_str()) == 0)
        {
                // This is one of the ones I want...I spend very little time
here.
        }

        // I spend 30 seconds here, in a loop...
}

My XML structure is like...
<PatchData>
    <CbName>abc</CbName>
    <Location>0</Location>
    <Type>0</Type>
    <Width>5.15</Width>
    <Enabled>true</Enabled>
</PatchData>
<PatchData>
    <CbName>abc</CbName>
    <Location>1</Location>
    <Type>1</Type>
    <Width>5.25</Width>
    <Enabled>false</Enabled>
</PatchData>

-dh


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to