class AdhocElement(Element): format_version = Attribute('version') name = Text('name-e') url = Child('url-e', AdhocTextElement, multiple=True) dob = Child('dob-e', AdhocTextElement, xmlns='http://example.com/')
class InspectXmlnsSetElement(Element): a = Child('child', XmlnsDoc, xmlns='http://dahlia.kr/')
class ELConsumeBufferRegressionTestDoc(DocumentElement): __tag__ = 'a' b = Child('b', ELConsumeBufferRegressionTestB, multiple=True)
class TestDoc(DocumentElement): __tag__ = 'test' attr_attr = Attribute('attr') attr_decoder = Attribute('attr-decoder', decoder=lambda s: s.lower()) attr_decoder_decorator = Attribute('attr-decoder-decorator') title_attr = Child('title', TextElement, required=True) content_attr = Child('content', TextElement, required=True) multi_attr = Child('multi', TextElement, multiple=True) sorted_children = Child('s-multi', TextElement, multiple=True, sort_key=lambda e: e.value) text_content_attr = Text('text-content') text_multi_attr = Text('text-multi', multiple=True) sorted_texts = Text('s-text-multi', multiple=True, sort_key=lambda t: t, sort_reverse=True) text_decoder = Text('text-decoder', decoder=float, encoder=str) text_decoder_decorator = Text('text-decoder-decorator') text_combined_decoder = Text('text-combined-decoder', decoder=int, encoder=lambda i: i and i / 100) ns_element_attr = Child('ns-element', TextElement, xmlns='http://earthreader.github.io/') ns_text_attr = Text('ns-text', xmlns='http://earthreader.github.io/') content_decoder = Child('content-decoder', TextDecoderElement) @attr_decoder_decorator.decoder def attr_decoder_decorator(self, value): return value[::-1] @attr_decoder_decorator.encoder def attr_decoder_decorator(self, value): return value and value[::-1] @text_decoder_decorator.decoder def text_decoder_decorator(self, text): return int(text[::-1]) @text_decoder_decorator.encoder def text_decoder_decorator(self, value): if value is not None: return str(value)[::-1] @text_combined_decoder.decoder def text_combined_decoder(self, value): return value * 100 @text_combined_decoder.decoder def text_combined_decoder(self, value): return -value @text_combined_decoder.encoder def text_combined_decoder(self, value): if value is not None: return -value @text_combined_decoder.encoder def text_combined_decoder(self, value): if value is not None: if value % 1 <= 0: value = int(value) return str(value)
class ELConsumeBufferRegressionTestB(Element): c = Child('c', ELConsumeBufferRegressionTestC, multiple=True)
class ELConsumeBufferRegressionTestC(Element): d = Child('d', ELConsumeBufferRegressionTestD)
class PartialLoadTestDoc(DocumentElement): __tag__ = 'partial-load-test' __xmlns__ = 'http://example.com/' entry = Child('entry', PartialLoadTestEntry, xmlns=__xmlns__)
class SelfReferentialChild(Element): self_ref = Child('self-ref', 'SelfReferentialChild')
class ChildDescriptorConflictElement(Element): child = Child('same-tag', TextElement) text = Text('same-tag')