AntaniXml


AntaniXml is a .NET library for generating random xml based on a schema.

This is useful mainly for testing, especially to produce stress test data, but also for unit and property based testing. Of course generating samples may also help in figuring out concretely what kind of xml is defined by a certain schema.

The library can be installed from NuGet:
PM> Install-Package AntaniXml

AntaniXml is developed in F# but the public API is usable also from C#. In fact most examples are given in both languages.

Example

The first example is straightforward, given a schema file you have to choose an element definition to use as a template. Then you call the Generate method to get the desired number of samples:

1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
#r "AntaniXml.dll"
open AntaniXml
open System.Xml

let samples = 
    Schema.CreateFromUri("po.xsd")
          .Generator(XmlQualifiedName "purchaseOrder")
          .Generate(10)

The C# code is almost the same:

1: 
2: 
3: 
var samples = Schema.CreateFromUri("po.xsd")
    .Generator(new XmlQualifiedName("purchaseOrder"))
    .Generate(10);

There is also a GenerateInfinite method allowing never ending sequences of random xml to be created on demand. This may be handy for stress testing so that you don't have to produce and store up-front huge amounts of data.

AntaniXml is built on top of the awesome FsCheck library, and you can use it for property based testing with FsCheck. Property based testing is an interesting and effective technique. FsCheck is well documented to get you started. This library provides Arbitrary instances so that you can feed tests with random (but valid) xml.

While the first example shows the easiest way to use the library, there is another public API allowing finer control on random generators. This API also exposes FsCheck types so that you can directly use their advanced features. Examples are available in the rest of the documentation.

Documentation

  • Tutorial contains a further explanation of this library.

  • Customizations hints at ways to tweak generators.

  • API Reference contains automatically generated documentation for all types, modules and functions in the library.

Contributing and copyright

The project is hosted on GitHub where you can report issues, fork the project and submit pull requests.

The library is available under a public domain license, which allows modification and redistribution for both commercial and non-commercial purposes. For more information see the License file in the GitHub repository.

namespace AntaniXml
namespace System
namespace System.Xml
val samples : Linq.XElement array

Full name: Index.samples
Multiple items
namespace System.Xml.Schema

--------------------
type Schema =
  new : xmlSchemaSet:XmlSchemaSet -> Schema
  member Arbitrary : elementName:XmlQualifiedName -> Arbitrary<XElement>
  member Arbitrary : elementName:XmlQualifiedName * customizations:CustomGenerators -> Arbitrary<XElement>
  member Generator : elementName:XmlQualifiedName -> IXmlElementGenerator
  member IsValid : element:XElement -> bool
  member Validate : element:XElement -> ValidationResult
  member Validate : element:string -> ValidationResult
  member GlobalElements : IEnumerable<XmlQualifiedName>
  static member CreateFromText : schemaText:string -> Schema
  static member CreateFromUri : schemaUri:string -> Schema

Full name: AntaniXml.Schema

--------------------
new : xmlSchemaSet:Schema.XmlSchemaSet -> Schema
static member Schema.CreateFromUri : schemaUri:string -> Schema
Multiple items
type XmlQualifiedName =
  new : unit -> XmlQualifiedName + 2 overloads
  member Equals : other:obj -> bool
  member GetHashCode : unit -> int
  member IsEmpty : bool
  member Name : string
  member Namespace : string
  member ToString : unit -> string
  static val Empty : XmlQualifiedName
  static member ToString : name:string * ns:string -> string

Full name: System.Xml.XmlQualifiedName

--------------------
XmlQualifiedName() : unit
XmlQualifiedName(name: string) : unit
XmlQualifiedName(name: string, ns: string) : unit
Fork me on GitHub