Hi Andreas,

This is a memory leak:

if (XMLString::compareString(node->getNodeName(),
XMLString::transcode("ConstraintTypes")) == 0)

because you are responsible for deleting the memory returned by
XMLString::transcode().  Also, these are invariant, so why not move them
out of the loop?

    const XMLCh* const   constraints =
XMLString::transcode("ConstraintTypes");

    ...

    delete [] constraints;

Dave



                                                                                       
                                  
                      "Andreas B.                                                      
                                  
                      Thun"                    To:      [EMAIL PROTECTED]              
                        
                      <[EMAIL PROTECTED]>            cc:      (bcc: David N 
Bertoni/Cambridge/IBM)                             
                                               Subject: Re: parsing DOM tree: how can 
I access two different siblings?   
                      03/20/2003 05:01                                                 
                                  
                      AM                                                               
                                  
                      Please respond                                                   
                                  
                      to xerces-c-dev                                                  
                                  
                                                                                       
                                  



> AccessControlGroups->getNextSibling()->getNextSibling() should return the
> Type element (not that I'm recommending such unsafe code!).

Safety is an issue, So I decided to scan it this (safer?!) way:

        // Find the XML doc root element
        DOMDocument *DomDoc = parser->getDocument();
        DOMElement  *rootElem = DomDoc->getDocumentElement();

        // Create tree walker
        DOMTreeWalker* walker = DomDoc->createTreeWalker(rootElem,
DOMNodeFilter::SHOW_ALL, 0, false);

        // Get first node
        DOMNode* node = walker->getCurrentNode();
        if (node->getNodeType() == DOMNode::ELEMENT_NODE)
        {
           // if current node is <ConstraintTypes> -> start tree walk
           if (XMLString::compareString(node->getNodeName(),
XMLString::transcode("ConstraintTypes")) == 0)
           {
              // start tree walk with first child (<AccessControlGroups> or
<Type>)
              node = walker->firstChild();
              while(node)
              {
                 if (node->getNodeType() == DOMNode::ELEMENT_NODE)
                 {
                    // <AccessControlGroups> (0 or 1)
                    if (XMLString::compareString(node->getNodeName(),
XMLString::transcode("AccessControlGroups")) == 0)
                    {
                       // do something
                    }

                    // <Type> (0 or more)
                    if (XMLString::compareString(node->getNodeName(),
XMLString::transcode("Type")) == 0)
                    {
                       // do something
                    }

                    // printNodeName(node);

                 }  // ELEMENT_NODE

                 node = walker->nextSibling();
              }
           }

        }



---------------------------------------------------------------------
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