You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xerces.apache.org by sk ask <ar...@yahoo.com> on 2002/03/19 09:20:54 UTC
NodeRefList to DOM_Nodes or DOM_NodeList?
Hi,
I am trying to get the selectListNodes method to
work.
Having a tough time returning a set of nodes
(converting from xalanNode to DOM nodes). Here is
the code. Can someone please point me to some
resources
or solution? Always get a crash in vector destructor
bool XMLReader::selectNodes(const TCHAR* xpathExpr,
std::vector<DOM_Node>& nodes)
{
// Set up a XercesParserLiaison and use it to wrap
the DOM_Document
// in a XalanDocument.
XercesDOMSupport theDOMSupport;
XercesParserLiaison theParserLiaison(theDOMSupport);
theParserLiaison.setDoNamespaces(m_parser->getDoNamespaces());
XalanDocument* theDoc =
theParserLiaison.createDocument(getDocument());
assert(theDoc);
XPathEvaluator theEvaluator;
// OK, let's find the context node...
NodeRefList const theContextNodes =
theEvaluator.selectNodeList(
theDOMSupport,theDoc,
XalanDOMString(xpathExpr).c_str(),
theDoc->getDocumentElement());
nodes.clear();
int numNodes = theContextNodes.getLength();
if(numNodes)
{
nodes.reserve(numNodes);
const XercesDocumentBridge* bridge=
theParserLiaison.mapDocument(theDoc);
if(bridge)
{
for(int i=0;i<numNodes;++i)
{
DOM_Node aNode =
bridge->mapNode(theContextNodes.item(i));
nodes.push_back(aNode);
}
return true;
}
}
return false;
}
//usage
void TestXmlReader()
{
CimfXMLReader reader;
reader.parseDoc("c:/temp/wpp/wpp3.xml",true,true,true);
bool retVal;
std::vector<DOM_Node> nodes;
if(reader.selectNodes("//x:Model",nodes))
{
std::vector<DOM_Node>::iterator it = nodes.begin();
for(;it != nodes.end();++it)
{
tstring str = reader.getAttValue("Type", (*it));
AfxMessageBox( str.c_str());
*it = 0;
}
}
nodes.clear();
}
=====
__________________________________________________
Do You Yahoo!?
Yahoo! Sports - live college hoops coverage
http://sports.yahoo.com/