XML文档自动生成在XML模式验证及网络环境下应用程序的测试中有广泛的应用.提出一种基于模式覆盖的XML文档自动生成方法,从给定模式中生成一组有效的且具有一定模式覆盖性的XML文档.采用正规树文法作为XML模式语言的形式模型,通过分析XML文档树与字符串之间的对应关系,将正规树文法转换为上下文无关文法,然后利用基于文法覆盖准则的句子生成算法从上下文无关文法中生成一组满足特定覆盖准则的句子,最后将句子还原为XML文档.实例分析和实验结果表明,生成的XML文档能较好地反映模式定义中的各种结构信息,可有效应用于XML模式验证及相关应用程序的功能测试.
Automatic generation of XML documents is widely used in XML schema validation and the testing of Web applications. This paper presents a schema covering based approach which,given an XML schema, generates a set of valid XML documents that a- chieves certain coverage for the schema. The approach takes regular tree grammar as the formal model of XML schema language. Based on the analysis of the relations between XML trees and strings,it first translates regular tree grammar to context-free grammar, then generates a set of sentences satisfying a given coverage criterion by utilizing coverage-based sentence generation algorithm for context-free grammar, and finally restores XML documents from those generated sentences. Case study and experimental results show that the generated XML documents can well reflect various structure constraints information in schema definitions, and can be effec- tively applied to XML schema validation as well as the functional testing of XML related applications.