code: private CmsResource findXmlPage(CmsObject cms, String resourcename) {
  
          // get the full folder path of the resource to start from
          String path = cms.getRequestContext().removeSiteRoot(resourcename);
          // the path without the trailing slash
          // for example: .../xmlpage.xml/ -> .../xmlpagepage.xml
          String reducedPath = CmsFileUtil.removeTrailingSeparator(path);
          do {
  
              // check if a resource without the trailing shalsh exists
              boolean existResource = cms.existsResource(reducedPath);
              // check if the current folder exists
              if (cms.existsResource(path) || existResource) {
                  // prove if a resource without the trailing slash does exist
                  if (existResource) {
                      // a resource without the trailing slash does exist, so take the path without the trailing slash
                      path = reducedPath;
                  }
                  try {
                      CmsResource res = cms.readResource(path);
                      I_CmsResourceType resType = OpenCms.getResourceManager().getResourceType(res.getTypeId());
                      if (resType instanceof CmsResourceTypeXmlPage) {
                          return res;
                      } else {
                          break;
                      }
                  } catch (CmsException ex) {
                      break;
                  }
  
              } else {
  
                  // folder does not exist, go up one folder
                  path = CmsResource.getParentFolder(path);
                  if (path.endsWith("/")) {
                      path = path.substring(0, path.length() - 1);
                  }
              }
  
              if (CmsStringUtil.isEmpty(path)) {
  
                  // site root or root folder reached and no folder found
                  break;
              }
          } while (true);
  
          return null;
      }
docs: Returns the {@link CmsResource} of the xml page which belongs to
  the given resource name (full path).<p>
  
  It works up the path till a resource for the path exists in the VFS.
  If the found resource is a xml page, this resource is returned. If
  the path does not belong to a xml page <code>null</code> will be returned.<p>
  
  @param cms the initialized CmsObject
  @param resourcename the name of the resource (full path) to check
  
  @return the found resource of type xml page or null if not found