title: My own method to execute xPath with Xercesc
body: <p>I use Xercesc library to parse XML's, but this library could execute only simple xPath's. I've written my own methot for execute xPath like this one:</p>
  
  <blockquote>
    <p>myProj/Parameters/Parameter[@Name="SomeName"]/Values/@DefaultValue</p>
  </blockquote>
  
  <p>but when I run my program I have "myProj.exe has triggered breakpoint" and I see "_CrtIsValidHeapPointer" method definition when debugging. When I avoid using my method - everything is ok, so something has to be wrong with my code, but I have no idea what. </p>
  
  <pre><code>        string executeXPath(const char *A_xmlFile, string xPathh, shared_ptr&lt;vector&lt;string&gt;&gt; sectionSqlVector)
      {
          scoped_ptr&lt;XercesDOMParser&gt; parser(new XercesDOMParser());
          parser-&gt;setValidationScheme(XercesDOMParser::Val_Always);
          parser-&gt;setDoNamespaces(true);    // optional
  
          scoped_ptr&lt;ErrorHandler&gt; errHandler((ErrorHandler*) new HandlerBase());
          parser-&gt;setErrorHandler(errHandler.get());
          parser-&gt;parse(A_xmlFile);
  
          const XMLCh* xPath = XMLString::transcode(xPathh.c_str());
          int pos = XMLString::indexOf(xPath,'@');
          int pos2 = XMLString::indexOf(xPath,('='));
          XMLCh* attrName = new XMLCh;
          XMLString::subString(attrName,xPath,pos+1,pos2);
  
          pos = XMLString::indexOf(xPath,'@', pos+1);
          XMLCh* attr2name = new XMLCh;
          XMLString::subString(attr2name, xPath, pos+1, XMLString::stringLen(xPath));
  
          pos = XMLString::indexOf(xPath,'"');
          XMLCh* attribute = new XMLCh;
          XMLString::subString(attribute, xPath, pos+1, XMLString::indexOf(xPath,'"',pos+1));
  
          DOMNode* docRootNode;
          DOMDocument* doc;
          doc = parser-&gt;getDocument();
          docRootNode = doc-&gt;getDocumentElement();
          DOMElement* elementRoot = doc-&gt;getDocumentElement();
          DOMNodeList* nodeList = elementRoot-&gt;getElementsByTagName(L"Parameter");
          XMLSize_t d = nodeList-&gt;getLength();
          string valuee = "";
          for (XMLSize_t i = 0; i &lt; d; i++)
          {
              DOMElement* tempElement = (DOMElement*)nodeList-&gt;item(i);
              if (tempElement-&gt;hasAttribute(attrName))
              {
                  const XMLCh* tempChar = tempElement-&gt;getAttribute(attrName);
                  if (XMLString::equals(attribute,tempChar))
                  {
                      DOMNodeList* tempList2 = tempElement-&gt;getElementsByTagName(L"Values");
                      DOMElement* tempElement2 = (DOMElement*)tempList2-&gt;item(0);
                      const XMLCh* defValue = tempElement2-&gt;getAttribute(attr2name);
                      valuee = XMLString::transcode(defValue);
                      tempElement2-&gt;release();
                  }
              }
              tempElement-&gt;release();
          }
          doc-&gt;release();
          elementRoot-&gt;release();
          docRootNode-&gt;release();
          XMLString::release(&amp;attr2name);
          XMLString::release(&amp;attrName);
          XMLString::release(&amp;attribute);
  
          return valuee;
  
      }
  </code></pre>