+namespace
+{
+
+// helper used by DoFindResource() and elsewhere: returns true if this is an
+// object or object_ref node
+//
+// node must be non-NULL
+inline bool IsObjectNode(wxXmlNode *node)
+{
+ return node->GetType() == wxXML_ELEMENT_NODE &&
+ (node->GetName() == wxS("object") ||
+ node->GetName() == wxS("object_ref"));
+}
+
+// special XML attribute with name of input file, see GetFileNameFromNode()
+const char *ATTR_INPUT_FILENAME = "__wx:filename";
+
+// helper to get filename corresponding to an XML node
+wxString
+GetFileNameFromNode(wxXmlNode *node, const wxXmlResourceDataRecords& files)
+{
+ // this loop does two things: it looks for ATTR_INPUT_FILENAME among
+ // parents and if it isn't used, it finds the root of the XML tree 'node'
+ // is in
+ for ( ;; )
+ {
+ // in some rare cases (specifically, when an <object_ref> is used, see
+ // wxXmlResource::CreateResFromNode() and MergeNodesOver()), we work
+ // with XML nodes that are not rooted in any document from 'files'
+ // (because a new node was created by CreateResFromNode() to merge the
+ // content of <object_ref> and the referenced <object>); in that case,
+ // we hack around the problem by putting the information about input
+ // file into a custom attribute
+ if ( node->HasAttribute(ATTR_INPUT_FILENAME) )
+ return node->GetAttribute(ATTR_INPUT_FILENAME);
+
+ if ( !node->GetParent() )
+ break; // we found the root of this XML tree
+
+ node = node->GetParent();
+ }
+
+ // NB: 'node' now points to the root of XML document
+
+ for ( wxXmlResourceDataRecords::const_iterator i = files.begin();
+ i != files.end(); ++i )
+ {
+ if ( (*i)->Doc->GetRoot() == node )
+ {
+ return (*i)->File;
+ }
+ }
+
+ return wxEmptyString; // not found
+}
+
+} // anonymous namespace
+