def test_attributes(self): x = XMLegant(); x.a = {'b':'c', 'd':'e'}; assert x.toXML(False) == '<a b="c" d="e" />', x.toXML(False) x.a['f'] = 'g'; assert x.toXML(False) == '<a b="c" d="e" f="g" />', x.toXML(False) assert x.a['f'] == 'g', x.a['f']
def test_simple(self): x = XMLegant(); x.a.b.c = 'd'; assert x.toXML(False) == '<a><b><c>d</c></b></a>', x.toXML(False) x.a.b.c = 'e' assert x.toXML(False) == '<a><b><c>e</c></b></a>', x.toXML(False) x.a.b = 'c' assert x.toXML(False) == '<a><b>c</b></a>', x.toXML(False) x.a = 'b' assert x.toXML(False) == '<a>b</a>', x.toXML(False) x.a.b = 'c' assert x.toXML(False) == '<a><b>c</b></a>', x.toXML(False)
x.a.h.n = 'o' """ The same document using chaining (The function getParent() is used to "move up" the tree) """ x = XMLegant() x.a() \ .b('c') \ .b('d') \ .e('f') \ .b('g') \ .h() \ .i('j', 'k') \ .l() \ .m('') \ .getParent() \ .n('o') """ Composing two XMLegant objects to create the following document: <a> <b> <d> <e>f</e>