1 2 3 4 5 6 7 8 | <!ELEMENT dissertation (dedication?, chapter+, appendix*)> <!ELEMENT dedication (#PCDATA)> <!ELEMENT chapter (title, paragraph+)> <!ELEMENT title (#PCDATA)> <!ELEMENT paragraph (#PCDATA | figure | table)> <!ELEMENT figure EMPTY> <!ELEMENT table EMPTY> <!ELEMENT appendix (#PCDATA)> |
1 2 3 4 5 | dissertation = Root.new [ Maybe_dedication.new, \ Some_chapter.new, \ Any_appendix.new ] # Example of accessing part of root element sequence dissertation.part[1].addchapter(some, arguments, here) |
1 2 3 4 5 6 7 8 | public class dissertation { Maybe dedication = new Maybe(dedication_type); Some chapters = new Some(chapter_type); Any appendices = new Any(appendix_type); Seq _seq = new Seq[] {dedication, chapters, appendices}; } /* Access is somewhat more natural now */ dissertation.chapter.add(some, arguments, here); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | class ExistentialList(UserList.UserList): def __init__(self, tag=None, initlist=[]): if tag is None: raise ValueError, "Must specify tag name" self.tag = tag UserList.UserList.__init__(self, initlist) def __delitem__(self, i): del self.data self.validate() def __repr__(self): self.validate() return'\n' .join([ '<%s>%s</%s>' % (self.tag, item, self.tag) for item in self.data]) def validate(self): ifnot len(initlist): raise"ExistentialError" , "List must have length >= 1" |
1 2 | class paragraph(Or): disjoins = (PCDATA, figure, table) |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |