To acquire a thermostable xylanase, that is suitable for xylooligosaccharide production from pretreated corncobs, the metagenomic method was used to obtain the gene from an uncultured environmental microorganism. A thermostable xylanase-encoding gene (xyn10CD18) was cloned directly from the metagenomic DNA of cow dung compost. When xyn10CD18 was expressed in Bacillus megaterium MS941, extracellular xylansae activity at 106 IU/ml was achieved. The purified recombinant Xyn10CD18 was optimally active at pH 7 and 75 °C as measured over 10 min. It retained over 55% of its initial activity at 70 °C and pH 7 after 24 h. Its action on birchwood xylan for 18 h liberated xylooligosaccharides with 2°-4° of polymerization, with xylobiose and xylotetraose as the main products. When pretreated corncobs were hydrolyzed by Xyn10CD18 for 18 h, the xylooligosaccharides (DP 2-4) products increased to 80% and the xylose was just increased by 3%. Xyn10CD18 is a thermostable endoxylanase and is a promising candidate for biomass conversion and xylooligosaccharide production.