The extensible markup language (XML), a standard format of web information, has a clear syntax but unfortunately an ambiguous formal semantics, which results in being not used directly in semantic web applications. So it is tough job to reuse XML-based data intelligently in the semantic web. To address this problem, a new formal technique of obtaining ontology data automatically from XML documents is proposed. We provide the XML a semantical interpretation by developing a graph-based formal language, which then can be automatically mapped into web ontology language OWL with semantics preserved. The semantic validity and entailment problem are also concerned. The automatical mapping tool has also been developed.