From: <axl...@us...> - 2009-04-18 13:47:12
|
Revision: 214 http://hgengine.svn.sourceforge.net/hgengine/?rev=214&view=rev Author: axlecrusher Date: 2009-04-18 13:44:00 +0000 (Sat, 18 Apr 2009) Log Message: ----------- search up parent tree first, then down Modified Paths: -------------- Mercury2/src/XMLParser.cpp Mercury2/src/XMLParser.h Modified: Mercury2/src/XMLParser.cpp =================================================================== --- Mercury2/src/XMLParser.cpp 2009-04-14 01:04:54 UTC (rev 213) +++ Mercury2/src/XMLParser.cpp 2009-04-18 13:44:00 UTC (rev 214) @@ -117,12 +117,24 @@ if (d) { - //start searching at the root - XMLNode root( xmlDocGetRootElement(m_doc), m_doc ); + MString path((const char*)d); + + int pos = path.find("."); + MString name = pos<=0?path:path.substr(0, pos); + MString rpath = pos<=0?"":path.substr(pos+1); //skip the period + + XMLNode parent = FindParentWithName( name ); + if ( !parent.IsValid() ) + { + //nothing found, do search down from root + parent = XMLNode( xmlDocGetRootElement(m_doc), m_doc ); + rpath = path; + } + //prevent infinite recursion on self - if ( root.m_node != m_node ) + if ( parent.m_node != m_node ) { - n = root.RecursiveFindFallbackNode( MString((const char*)d) ); + n = parent.RecursiveFindFallbackNode( rpath ); } xmlFree(d); } @@ -130,6 +142,19 @@ return n; } +XMLNode XMLNode::FindParentWithName(const MString& name) const +{ + if ( (!name.empty()) && (m_node->parent) ) + { + XMLNode parent(m_node->parent, m_doc); + if (parent.Attribute("name") == name) + return parent; + return parent.FindParentWithName( name ); + } + return XMLNode(); +} + + XMLNode XMLNode::RecursiveFindFallbackNode(const MString& path) const { if ( !IsValid() ) return XMLNode(); Modified: Mercury2/src/XMLParser.h =================================================================== --- Mercury2/src/XMLParser.h 2009-04-14 01:04:54 UTC (rev 213) +++ Mercury2/src/XMLParser.h 2009-04-18 13:44:00 UTC (rev 214) @@ -37,6 +37,7 @@ const XMLNode& operator=(const XMLNode& n); private: XMLNode RecursiveFindFallbackNode(const MString& path) const; + XMLNode FindParentWithName(const MString& name) const; xmlNode* m_node; xmlDoc* m_doc; //parent doc, don't free This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |