def test_addingBulkChildren(self): """ Suppose you want to easily create the structure <books> <book> <title>Title 1</title> <author>Author 1</author> <isbn>isbn1</isbn> </book> <book> <title>Title 2</title> <author>Author 2</author> <isbn>isbn2</isbn> </book> <book> <title>Title 2</title> <author>Author 2</author> <isbn>isbn2</isbn> </book> ... </books> """ book_data = XMLegant() x = XMLegant() for i in xrange(5): book_data.title = "Title "+str(i) book_data.author = "Author "+str(i) book_data.isbn = "isbn "+str(i) x.books.book(book_data) assert x.toXML(False) == '<books><book><title>Title 0</title><author>Author 0</author><isbn>isbn 0</isbn></book><book><title>Title 1</title><author>Author 1</author><isbn>isbn 1</isbn></book><book><title>Title 2</title><author>Author 2</author><isbn>isbn 2</isbn></book><book><title>Title 3</title><author>Author 3</author><isbn>isbn 3</isbn></book><book><title>Title 4</title><author>Author 4</author><isbn>isbn 4</isbn></book></books>', x.toXML(False)
<isbn>isbn 2</isbn> </book> <book> <title>Title 3</title> <author>Author 3</author> <isbn>isbn 3</isbn> </book> ... </books> """ x = XMLegant() book_data = XMLegant() for i in xrange(5): book_data.title = "Title %d" % i book_data.author = "Author %d" % i book_data.isbn = "isbn %d" % i x.books.book(book_data) """ Or using chaining """ x = XMLegant() for i in xrange(5): x.books.book(XMLegant().title("Title %d" % i) \ .author("Author %d" % i) \ .isbn("isbn %d" % i))