2007年10月21日 星期日 14:04
´úÂëÈçÏ£º LANG_BEGIN = 3 ROOT = 'myroot' VALUE = 'value' KEY = 'key' NODE = 'res' class WriteXmlError(Exception) : pass class ReadXMLError(Exception) : pass class WriteBadKeyError(Exception) : pass class WriteBadValueError(Exception) : pass class ReadBadKeyError(Exception) : pass class ReadBadValueError(Exception) : pass class InitXmlError(Exception) : pass class CreateChildError(Exception) : pass class PtWriteXml : def __init__(self, xmlFile): try: self.__ok = 1 impl = xml.dom.minidom.getDOMImplementation() self.doc = impl.createDocument(None, 'catalog', None) self.root = self.doc.documentElement except Exception: self.__ok = 0 raise InitXmlError else: self.__ok = 1 def close(self): try: file = open(xmlFile, 'w') writer = codecs.lookup('utf-8')[3](file) self.doc.writexml(writer=writer, indent='', addindent='\t', newl='\n', encoding=u'utf-8') except Exception: raise WriteXmlError def addResItem(self, key, value): if not self.__ok: return try: text = self.doc.createTextNode('nothing') item = self.doc.CreateElement('caption') * #´Ë´¦×ÜÊÇ»áÒýÆðÒì³££¬ÎªÊ²Ã´£¿* try: key + '' item.setAttribute(KEY, key) except Exception: raise WriteBadKeyError try: value + '' item.setAttribute(VALUE, value) except Exception: raise WriteBadValueError self.root.appendChild(item) except Exception: print 'append child node error : %s' % key self.__ok = 0 raise CreateChildError ** *µ«ÊÇ£¬Èç¹ûÎÒÓÃÏÂÃæµÄ·ÇÀà·â×°µÄ´úÂ룬¾ÍûÓÐÎÊÌ⣺* import xml.dom.minidom try: impl = xml.dom.minidom.getDOMImplementation() dom = impl.createDocument(None, 'catalog', None) root = dom.documentElement text = dom.createTextNode('nothing') item = dom.createElement('caption') *#ÕâÀï²»»áÒýÆðÒì³££¬ÎªÊ²Ã´£¿* item.appendChild(text) item.setAttribute('id', 'id value') root.appendChild(item) print root.toxml() file = open(r'd:\1.xml', 'w') import codecs writer = codecs.lookup('utf-8')[3](file) print dom.toxml() dom.writexml(writer=writer, indent='', addindent='\t', newl='\n', encoding=u'utf-8') writer.close() except: print 'exception occur' *ÊÇÎÒÀàµÄÓï·¨²»¶Ô£¬»¹ÊÇÔõô»ØÊÂѽ£¿£¿* -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20071021/cee99dca/attachment.html
2007年10月21日 星期日 14:12
ûÓùýÕâ¸ödom µ«ÊÇÄãÉÏÃæµÄ´úÂëºÍÏÂÃæµÄ´úÂë createElement ´óСд¶¼²»Ò»Ñù¡£ On 10/21/07, ??? ?? <clfff.peter在gmail.com> wrote: > > ´úÂëÈçÏ£º > > > LANG_BEGIN = 3 > ROOT = 'myroot' > VALUE = 'value' > KEY = 'key' > NODE = 'res' > > class WriteXmlError(Exception) : pass > class ReadXMLError(Exception) : pass > class WriteBadKeyError(Exception) : pass > class WriteBadValueError(Exception) : pass > class ReadBadKeyError(Exception) : pass > class ReadBadValueError(Exception) : pass > class InitXmlError(Exception) : pass > class CreateChildError(Exception) : pass > > > class PtWriteXml : > def __init__(self, xmlFile): > try: > self.__ok = 1 > impl = xml.dom.minidom.getDOMImplementation() > self.doc = impl.createDocument(None, 'catalog', None) > self.root = self.doc.documentElement > except Exception: > self.__ok = 0 > raise InitXmlError > else: > self.__ok = 1 > > def close(self): > try: > file = open(xmlFile, 'w') > writer = codecs.lookup('utf-8')[3](file) > self.doc.writexml(writer=writer, indent='', addindent='\t', > newl='\n', encoding=u'utf-8') > except Exception: > raise WriteXmlError > > def addResItem(self, key, value): > if not self.__ok: > return > try: > text = self.doc.createTextNode ('nothing') > item = self.doc.CreateElement('caption') * #´Ë´¦×ÜÊÇ»áÒýÆðÒì³££¬ÎªÊ²Ã´£¿* > try: > key + '' > item.setAttribute(KEY, key) > except Exception: > raise WriteBadKeyError > try: > value + '' > item.setAttribute(VALUE, value) > except Exception: > raise WriteBadValueError > self.root.appendChild(item) > except Exception: > print 'append child node error : %s' % key > self.__ok = 0 > raise CreateChildError > ** > > *µ«ÊÇ£¬Èç¹ûÎÒÓÃÏÂÃæµÄ·ÇÀà·â×°µÄ´úÂ룬¾ÍûÓÐÎÊÌ⣺* > > import xml.dom.minidom > try: > impl = xml.dom.minidom.getDOMImplementation() > dom = impl.createDocument(None, 'catalog', None) > root = dom.documentElement > text = dom.createTextNode('nothing') > item = dom.createElement('caption') *#ÕâÀï²»»áÒýÆðÒì³££¬ÎªÊ²Ã´£¿* > item.appendChild(text) > item.setAttribute('id', 'id value') > root.appendChild(item) > print root.toxml () > file = open(r'd:\1.xml', 'w') > import codecs > writer = codecs.lookup('utf-8')[3](file) > print dom.toxml() > dom.writexml(writer=writer, indent='', addindent='\t', newl='\n', > encoding=u'utf-8') > writer.close() > except: > print 'exception occur' > > > *ÊÇÎÒÀàµÄÓï·¨²»¶Ô£¬»¹ÊÇÔõô»ØÊÂѽ£¿£¿* > > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20071021/979cb2b7/attachment-0001.html
2007年10月22日 星期一 11:16
²ÑÀ¢Ñ½£¬²ÑÀ¢Ñ½£¬º¹ËÀÁË¡£ ¶àлÄãѽ£¬ÎÒÕÛÌÚÁË°ëÌ죬лллл¡£ ÔÚ07-10-21£¬@@ <askfor在gmail.com> дµÀ£º > > ûÓùýÕâ¸ödom > µ«ÊÇÄãÉÏÃæµÄ´úÂëºÍÏÂÃæµÄ´úÂë createElement ´óСд¶¼²»Ò»Ñù¡£ > > > On 10/21/07, ??? ?? <clfff.peter在gmail.com> wrote: > > > ´úÂëÈçÏ£º > > > > > > LANG_BEGIN = 3 > > ROOT = 'myroot' > > VALUE = 'value' > > KEY = 'key' > > NODE = 'res' > > > > class WriteXmlError(Exception) : pass > > class ReadXMLError(Exception) : pass > > class WriteBadKeyError(Exception) : pass > > class WriteBadValueError(Exception) : pass > > class ReadBadKeyError(Exception) : pass > > class ReadBadValueError(Exception) : pass > > class InitXmlError(Exception) : pass > > class CreateChildError(Exception) : pass > > > > > > class PtWriteXml : > > def __init__(self, xmlFile): > > try: > > self.__ok = 1 > > impl = xml.dom.minidom.getDOMImplementation() > > self.doc = impl.createDocument(None, 'catalog', None) > > self.root = self.doc.documentElement > > except Exception: > > self.__ok = 0 > > raise InitXmlError > > else: > > self.__ok = 1 > > > > def close(self): > > try: > > file = open(xmlFile, 'w') > > writer = codecs.lookup('utf-8')[3](file) > > self.doc.writexml(writer=writer, indent='', addindent='\t', > > newl='\n', encoding=u'utf-8') > > except Exception: > > raise WriteXmlError > > > > def addResItem(self, key, value): > > if not self.__ok: > > return > > try: > > text = self.doc.createTextNode ('nothing') > > item = self.doc.CreateElement('caption') * #´Ë´¦×ÜÊÇ»áÒýÆðÒì³££¬ÎªÊ²Ã´£¿* > > try: > > key + '' > > item.setAttribute(KEY, key) > > except Exception: > > raise WriteBadKeyError > > try: > > value + '' > > item.setAttribute(VALUE, value) > > except Exception: > > raise WriteBadValueError > > self.root.appendChild(item) > > except Exception: > > print 'append child node error : %s' % key > > self.__ok = 0 > > raise CreateChildError > > ** > > > > *µ«ÊÇ£¬Èç¹ûÎÒÓÃÏÂÃæµÄ·ÇÀà·â×°µÄ´úÂ룬¾ÍûÓÐÎÊÌ⣺* > > > > import xml.dom.minidom > > try: > > impl = xml.dom.minidom.getDOMImplementation() > > dom = impl.createDocument(None, 'catalog', None) > > root = dom.documentElement > > text = dom.createTextNode('nothing') > > item = dom.createElement('caption') *#ÕâÀï²»»áÒýÆðÒì³££¬ÎªÊ²Ã´£¿* > > item.appendChild(text) > > item.setAttribute('id', 'id value') > > root.appendChild(item) > > print root.toxml () > > file = open(r'd:\1.xml', 'w') > > import codecs > > writer = codecs.lookup('utf-8')[3](file) > > print dom.toxml() > > dom.writexml(writer=writer, indent='', addindent='\t', newl='\n', > > encoding=u'utf-8') > > writer.close() > > except: > > print 'exception occur' > > > > > > *ÊÇÎÒÀàµÄÓï·¨²»¶Ô£¬»¹ÊÇÔõô»ØÊÂѽ£¿£¿* > > > > _______________________________________________ > > python-chinese > > Post: send python-chinese在lists.python.cn > > Subscribe: send subscribe to python-chinese-request在lists.python.cn > > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > > > > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20071022/dbf13a28/attachment.html
2007年10月22日 星期一 11:19
µÈÄã·â×°ºÃÁËºó ·¢Ò»·ÝÉÏÀ´ºÃÂð? ×î½üÕýºÃÒªÓÃXMLµÄ¶Áд ----- Original Message ----- From: ??? ?? To: python-chinese在lists.python.cn Sent: Monday, October 22, 2007 11:16 AM Subject: Re: [python-chinese]ÓжγÌÐò£¬ÊÇдxmlÎļþµÄ£¬ÎÒÏë°ÑËü×ö³ÉÀ࣬µ«ÊÇ×ö³ÉÀàÖ®ºó¾Í²»ÄÜÕý³£¹¤×÷ÁË£¬ÎªÊ²Ã´£¿ ²ÑÀ¢Ñ½£¬²ÑÀ¢Ñ½£¬º¹ËÀÁË¡£ ¶àлÄãѽ£¬ÎÒÕÛÌÚÁË°ëÌ죬лллл¡£ ÔÚ07-10-21£¬@@ <askfor在gmail.com> дµÀ£º ûÓùýÕâ¸ödom µ«ÊÇÄãÉÏÃæµÄ´úÂëºÍÏÂÃæµÄ´úÂë createElement ´óСд¶¼²»Ò»Ñù¡£ On 10/21/07, ??? ?? < clfff.peter在gmail.com> wrote: ´úÂëÈçÏ£º LANG_BEGIN = 3 ROOT = 'myroot' VALUE = 'value' KEY = 'key' NODE = 'res' class WriteXmlError(Exception) : pass class ReadXMLError(Exception) : pass class WriteBadKeyError(Exception) : pass class WriteBadValueError(Exception) : pass class ReadBadKeyError(Exception) : pass class ReadBadValueError(Exception) : pass class InitXmlError(Exception) : pass class CreateChildError(Exception) : pass class PtWriteXml : def __init__(self, xmlFile): try: self.__ok = 1 impl = xml.dom.minidom.getDOMImplementation() self.doc = impl.createDocument(None, 'catalog', None) self.root = self.doc.documentElement except Exception: self.__ok = 0 raise InitXmlError else: self.__ok = 1 def close(self): try: file = open(xmlFile, 'w') writer = codecs.lookup('utf-8')[3](file) self.doc.writexml(writer=writer, indent='', addindent='\t', newl='\n', encoding=u'utf-8') except Exception: raise WriteXmlError def addResItem(self, key, value): if not self.__ok: return try: text = self.doc.createTextNode ('nothing') item = self.doc.CreateElement('caption') #´Ë´¦×ÜÊÇ»áÒýÆðÒì³££¬ÎªÊ²Ã´£¿ try: key + '' item.setAttribute(KEY, key) except Exception: raise WriteBadKeyError try: value + '' item.setAttribute(VALUE, value) except Exception: raise WriteBadValueError self.root.appendChild(item) except Exception: print 'append child node error : %s' % key self.__ok = 0 raise CreateChildError µ«ÊÇ£¬Èç¹ûÎÒÓÃÏÂÃæµÄ·ÇÀà·â×°µÄ´úÂ룬¾ÍûÓÐÎÊÌ⣺ import xml.dom.minidom try: impl = xml.dom.minidom.getDOMImplementation() dom = impl.createDocument(None, 'catalog', None) root = dom.documentElement text = dom.createTextNode('nothing') item = dom.createElement('caption') #ÕâÀï²»»áÒýÆðÒì³££¬ÎªÊ²Ã´£¿ item.appendChild(text) item.setAttribute('id', 'id value') root.appendChild(item) print root.toxml () file = open(r'd:\1.xml', 'w') import codecs writer = codecs.lookup('utf-8')[3](file) print dom.toxml() dom.writexml(writer=writer, indent='', addindent='\t', newl='\n', encoding=u'utf-8') writer.close() except: print 'exception occur' ÊÇÎÒÀàµÄÓï·¨²»¶Ô£¬»¹ÊÇÔõô»ØÊÂѽ£¿£¿ _______________________________________________ python-chinese Post: send python-chinese在lists.python.cn Subscribe: send subscribe to python-chinese-request在lists.python.cn Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn Detail Info: http://python.cn/mailman/listinfo/python-chinese _______________________________________________ python-chinese Post: send python-chinese在lists.python.cn Subscribe: send subscribe to python-chinese-request在lists.python.cn Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn Detail Info: http://python.cn/mailman/listinfo/python-chinese ------------------------------------------------------------------------------ _______________________________________________ python-chinese Post: send python-chinese在lists.python.cn Subscribe: send subscribe to python-chinese-request在lists.python.cn Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn Detail Info: http://python.cn/mailman/listinfo/python-chinese -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20071022/c64dbb4b/attachment.html
2007年10月22日 星期一 13:21
ÊǺܼòµ¥µÄ£¬ÒòΪÊÇ×ö¶à¹úÓïÑÔÓõģ¬ËùÒԽṹÊÇ£ºÔÚ07-10-22£¬xuanll <xuanll在zctt.com.cn> дµÀ£º > > µÈÄã·â×°ºÃÁËºó ·¢Ò»·ÝÉÏÀ´ºÃÂð? > ×î½üÕýºÃÒªÓÃXMLµÄ¶Áд > > > ----- Original Message ----- > *From:* ??? ?? <clfff.peter在gmail.com> > *To:* python-chinese在lists.python.cn > *Sent:* Monday, October 22, 2007 11:16 AM > *Subject:* Re: [python-chinese]ÓжγÌÐò£¬ÊÇдxmlÎļþµÄ£¬ÎÒÏë°ÑËü×ö³ÉÀ࣬µ«ÊÇ×ö³ÉÀàÖ®ºó¾Í²»ÄÜÕý³£¹¤×÷ÁË£¬ÎªÊ²Ã´£¿ > > > ²ÑÀ¢Ñ½£¬²ÑÀ¢Ñ½£¬º¹ËÀÁË¡£ > ¶àлÄãѽ£¬ÎÒÕÛÌÚÁË°ëÌ죬лллл¡£ > > > ÔÚ07-10-21£¬@@ <askfor在gmail.com> дµÀ£º > > > > ûÓùýÕâ¸ödom > > µ«ÊÇÄãÉÏÃæµÄ´úÂëºÍÏÂÃæµÄ´úÂë createElement ´óСд¶¼²»Ò»Ñù¡£ > > > > > > On 10/21/07, ??? ?? < clfff.peter在gmail.com> wrote: > > > > > ´úÂëÈçÏ£º > > > > > > > > > LANG_BEGIN = 3 > > > ROOT = 'myroot' > > > VALUE = 'value' > > > KEY = 'key' > > > NODE = 'res' > > > > > > class WriteXmlError(Exception) : pass > > > class ReadXMLError(Exception) : pass > > > class WriteBadKeyError(Exception) : pass > > > class WriteBadValueError(Exception) : pass > > > class ReadBadKeyError(Exception) : pass > > > class ReadBadValueError(Exception) : pass > > > class InitXmlError(Exception) : pass > > > class CreateChildError(Exception) : pass > > > > > > > > > class PtWriteXml : > > > def __init__(self, xmlFile): > > > try: > > > self.__ok = 1 > > > impl = xml.dom.minidom.getDOMImplementation() > > > self.doc = impl.createDocument(None, 'catalog', None) > > > self.root = self.doc.documentElement > > > except Exception: > > > self.__ok = 0 > > > raise InitXmlError > > > else: > > > self.__ok = 1 > > > > > > def close(self): > > > try: > > > file = open(xmlFile, 'w') > > > writer = codecs.lookup('utf-8')[3](file) > > > self.doc.writexml(writer=writer, indent='', > > > addindent='\t', newl='\n', encoding=u'utf-8') > > > except Exception: > > > raise WriteXmlError > > > > > > def addResItem(self, key, value): > > > if not self.__ok: > > > return > > > try: > > > text = self.doc.createTextNode ('nothing') > > > item = self.doc.CreateElement('caption') * #´Ë´¦×ÜÊÇ»áÒýÆðÒì³££¬ÎªÊ²Ã´£¿ > > > * > > > try: > > > key + '' > > > item.setAttribute(KEY, key) > > > except Exception: > > > raise WriteBadKeyError > > > try: > > > value + '' > > > item.setAttribute(VALUE, value) > > > except Exception: > > > raise WriteBadValueError > > > self.root.appendChild(item) > > > except Exception: > > > print 'append child node error : %s' % key > > > self.__ok = 0 > > > raise CreateChildError > > > ** > > > > > > *µ«ÊÇ£¬Èç¹ûÎÒÓÃÏÂÃæµÄ·ÇÀà·â×°µÄ´úÂ룬¾ÍûÓÐÎÊÌ⣺* > > > > > > import xml.dom.minidom > > > try: > > > impl = xml.dom.minidom.getDOMImplementation() > > > dom = impl.createDocument(None, 'catalog', None) > > > root = dom.documentElement > > > text = dom.createTextNode('nothing') > > > item = dom.createElement('caption') *#ÕâÀï²»»áÒýÆðÒì³££¬ÎªÊ²Ã´£¿* > > > item.appendChild(text) > > > item.setAttribute('id', 'id value') > > > root.appendChild(item) > > > print root.toxml () > > > file = open(r'd:\1.xml', 'w') > > > import codecs > > > writer = codecs.lookup('utf-8')[3](file) > > > print dom.toxml() > > > dom.writexml(writer=writer, indent='', addindent='\t', newl='\n', > > > encoding=u'utf-8') > > > writer.close() > > > except: > > > print 'exception occur' > > > > > > > > > *ÊÇÎÒÀàµÄÓï·¨²»¶Ô£¬»¹ÊÇÔõô»ØÊÂѽ£¿£¿* > > > > > > _______________________________________________ > > > python-chinese > > > Post: send python-chinese在lists.python.cn > > > Subscribe: send subscribe to python-chinese-request在lists.python.cn > > > Unsubscribe: send unsubscribe to > > > python-chinese-request在lists.python.cn > > > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > > > > > > > > _______________________________________________ > > python-chinese > > Post: send python-chinese在lists.python.cn > > Subscribe: send subscribe to python-chinese-request在lists.python.cn > > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > > > > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > > > ------------------------------ > > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20071022/d2007c03/attachment-0001.html
2007年10月22日 星期一 13:27
²»ºÃÒâ˼£¬¼üÅÌÌ«ºÃÁË¡£ ÊǺܼòµ¥µÄ£¬ÒòΪÊÇ×ö¶à¹úÓïÑÔÓõģ¬ËùÒԽṹÊÇ£º<......> Ö»ÓÐÒ»¸ö¸¸×ӵIJ㼶£¬Ö®ËùÒÔд¸öÀàÊÇÒòΪÎÒÊÇpython²ÆÄñ£¬ÏëÁ·Á·ÊÖ£¬¶øÇÒÏëÊÔÑéÏÂunittest¡£µÈÎÒдºÃÁ˽«unittestÒ»¿é´«ÉÏÀ´£¬²»¹ý¶Ô´ó¼Ò¿ÉÄÜûʲôÓá£( ^__^ ) ÔÚ07-10-22£¬??? ?? <clfff.peter在gmail.com> дµÀ£º > > ÊǺܼòµ¥µÄ£¬ÒòΪÊÇ×ö¶à¹úÓïÑÔÓõģ¬ËùÒԽṹÊÇ£º > > > > > ÔÚ07-10-22£¬xuanll <xuanll在zctt.com.cn> дµÀ£º > > > > µÈÄã·â×°ºÃÁËºó ·¢Ò»·ÝÉÏÀ´ºÃÂð? > > ×î½üÕýºÃÒªÓÃXMLµÄ¶Áд > > > > > > ----- Original Message ----- > > *From:* ??? ?? <clfff.peter在gmail.com> > > *To:* python-chinese在lists.python.cn > > *Sent:* Monday, October 22, 2007 11:16 AM > > *Subject:* Re: > > [python-chinese]ÓжγÌÐò£¬ÊÇдxmlÎļþµÄ£¬ÎÒÏë°ÑËü×ö³ÉÀ࣬µ«ÊÇ×ö³ÉÀàÖ®ºó¾Í²»ÄÜÕý³£¹¤×÷ÁË£¬ÎªÊ²Ã´£¿ > > > > > > ²ÑÀ¢Ñ½£¬²ÑÀ¢Ñ½£¬º¹ËÀÁË¡£ > > ¶àлÄãѽ£¬ÎÒÕÛÌÚÁË°ëÌ죬лллл¡£ > > > > > > ÔÚ07-10-21£¬@@ <askfor在gmail.com > дµÀ£º > > > > > > ûÓùýÕâ¸ödom > > > µ«ÊÇÄãÉÏÃæµÄ´úÂëºÍÏÂÃæµÄ´úÂë createElement ´óСд¶¼²»Ò»Ñù¡£ > > > > > > > > > On 10/21/07, ??? ?? < clfff.peter在gmail.com> wrote: > > > > > > > ´úÂëÈçÏ£º > > > > > > > > > > > > LANG_BEGIN = 3 > > > > ROOT = 'myroot' > > > > VALUE = 'value' > > > > KEY = 'key' > > > > NODE = 'res' > > > > > > > > class WriteXmlError(Exception) : pass > > > > class ReadXMLError(Exception) : pass > > > > class WriteBadKeyError(Exception) : pass > > > > class WriteBadValueError(Exception) : pass > > > > class ReadBadKeyError(Exception) : pass > > > > class ReadBadValueError(Exception) : pass > > > > class InitXmlError(Exception) : pass > > > > class CreateChildError(Exception) : pass > > > > > > > > > > > > class PtWriteXml : > > > > def __init__(self, xmlFile): > > > > try: > > > > self.__ok = 1 > > > > impl = xml.dom.minidom.getDOMImplementation() > > > > self.doc = impl.createDocument(None, 'catalog', None) > > > > self.root = self.doc.documentElement > > > > except Exception: > > > > self.__ok = 0 > > > > raise InitXmlError > > > > else: > > > > self.__ok = 1 > > > > > > > > def close(self): > > > > try: > > > > file = open(xmlFile, 'w') > > > > writer = codecs.lookup('utf-8')[3](file) > > > > self.doc.writexml(writer=writer, indent='', > > > > addindent='\t', newl='\n', encoding=u'utf-8') > > > > except Exception: > > > > raise WriteXmlError > > > > > > > > def addResItem(self, key, value): > > > > if not self.__ok: > > > > return > > > > try: > > > > text = self.doc.createTextNode ('nothing') > > > > item = self.doc.CreateElement('caption') *#´Ë´¦×ÜÊÇ»áÒýÆðÒì³££¬ÎªÊ²Ã´£¿ > > > > * > > > > try: > > > > key + '' > > > > item.setAttribute(KEY, key) > > > > except Exception: > > > > raise WriteBadKeyError > > > > try: > > > > value + '' > > > > item.setAttribute(VALUE, value) > > > > except Exception: > > > > raise WriteBadValueError > > > > self.root.appendChild(item) > > > > except Exception: > > > > print 'append child node error : %s' % key > > > > self.__ok = 0 > > > > raise CreateChildError > > > > ** > > > > > > > > *µ«ÊÇ£¬Èç¹ûÎÒÓÃÏÂÃæµÄ·ÇÀà·â×°µÄ´úÂ룬¾ÍûÓÐÎÊÌ⣺* > > > > > > > > import xml.dom.minidom > > > > try: > > > > impl = xml.dom.minidom.getDOMImplementation() > > > > dom = impl.createDocument(None, 'catalog', None) > > > > root = dom.documentElement > > > > text = dom.createTextNode('nothing') > > > > item = dom.createElement('caption') *#ÕâÀï²»»áÒýÆðÒì³££¬ÎªÊ²Ã´£¿* > > > > item.appendChild(text) > > > > item.setAttribute('id', 'id value') > > > > root.appendChild(item) > > > > print root.toxml () > > > > file = open(r'd:\1.xml', 'w') > > > > import codecs > > > > writer = codecs.lookup('utf-8')[3](file) > > > > print dom.toxml() > > > > dom.writexml(writer=writer, indent='', addindent='\t', > > > > newl='\n', encoding=u'utf-8') > > > > writer.close() > > > > except: > > > > print 'exception occur' > > > > > > > > > > > > *ÊÇÎÒÀàµÄÓï·¨²»¶Ô£¬»¹ÊÇÔõô»ØÊÂѽ£¿£¿* > > > > > > > > _______________________________________________ > > > > python-chinese > > > > Post: send python-chinese在lists.python.cn > > > > Subscribe: send subscribe to python-chinese-request在lists.python.cn > > > > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > > > > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > > > > > > > > > > > > _______________________________________________ > > > python-chinese > > > Post: send python-chinese在lists.python.cn > > > Subscribe: send subscribe to python-chinese-request在lists.python.cn > > > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > > > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > > > > > > ------------------------------ > > > > _______________________________________________ > > python-chinese > > Post: send python-chinese在lists.python.cn > > Subscribe: send subscribe to python-chinese-request在lists.python.cn > > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > > > > > _______________________________________________ > > python-chinese > > Post: send python-chinese在lists.python.cn > > Subscribe: send subscribe to python-chinese-request在lists.python.cn > > Unsubscribe: send unsubscribe to > > python-chinese-request在lists.python.cn > > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > > > -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20071022/1fce362f/attachment-0001.htm
2007年10月22日 星期一 14:10
用python为什么还用xml,如果不需要和其他程序交互直接用代码做配置文件。 在 07-10-22,??? ??<clfff.peter在gmail.com> 写道: > 不好意思,键盘太好了。 > > 是很简单的,因为是做多国语言用的,所以结构是: >> > >
2007年10月22日 星期一 14:29
Õâ¸ö½Å±¾ÊÇΪvc³ÌÐòдµÄ£¬ÒÔÇ°ÓÐÒ»¸öÀàËƵÄc³ÌÐò£¬²»¹ýÓÐЩÎÊÌ⣬¸É´à¾ÍÏëÓÃpythonÖØдһÏ¡£ ÔÚ07-10-22£¬vicalloy <zbirder在gmail.com> дµÀ£º > > ÓÃpythonΪʲô»¹ÓÃxml£¬Èç¹û²»ÐèÒªºÍÆäËû³ÌÐò½»»¥Ö±½ÓÓôúÂë×öÅäÖÃÎļþ¡£ > > ÔÚ 07-10-22£¬??? ??<clfff.peter在gmail.com> дµÀ£º > > ²»ºÃÒâ˼£¬¼üÅÌÌ«ºÃÁË¡£ > > > > ÊǺܼòµ¥µÄ£¬ÒòΪÊÇ×ö¶à¹úÓïÑÔÓõģ¬ËùÒԽṹÊÇ£º > >> > > > > > > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20071022/502ddea7/attachment.htm
Zeuux © 2025
京ICP备05028076号