python ÖÐminidom½âÎöxml
python ÖÐminidom½âÎöxml
2009Äê06ÔÂ26ÈÕ ÐÇÆÚÎå 08:40
ÏÂÃæÖ»ÁгöһЩ³£Óõķ½·¨ÊôÐÔ£¬Èç¹ûÒª²é¿´¸ü¶àµÄ·½·¨£¬ ¿ÉÒÔÈ¥¿´ÎļþminidomÈçºÎʵÏֵġ£
»ñµÃDocument¶ÔÏó
·¨Ò»£º
import xml.dom.minidom as m_dom
doc1 = m_dom.getDOMImplementation().createDocument(None, "root1", None)
doc1.documentElement.toxml(encoding="utf-8")
'<root1/>'
·¨¶þ£º
s = "<node><xxxx/></node>"
doc2 = m_dom.parseString(s)
print doc2.toprettyxml(indent=" ", newl="\n", encoding="utf-8")
<?xml version="1.0" encoding="utf-8"?>
<node>
<xxxx/>
</node>
»ñµÃ¸ú½Úµã£º
rt = doc1.documentElement
´´½¨½Úµã£º
node1 = doc1.createElement("node1")
rt.appendChild(node1)
rt.toxml()
'<root1><node1/></root1>'
ÉèÖÃ/»ñµÃÊôÐÔ£º
node1.setAttribute("name", "name1")
rt.toxml()
'<root1><node1 name="name1"/></root1>'
node1.getAttribute("name")
'name1'
´´½¨Êý¾Ý½Úµã£º
dt = doc1.createTextNode("the datas.")
node1.appendChild(dt)
rt.toxml()
'<root1><node1 name="name1">the datas.</node1></root1>'
node1.firstChild.toxml()
'the datas.'
»ñµÃ×ӽڵ㣺
node1
<DOM Element: node1 at 0xed0aa8>
rt.childNodes
[<DOM Element: node1 at 0xed0aa8>]
rt.getElementsByTagName("node1")
[<DOM Element: node1 at 0xed0aa8>]
rt.firstChild
<DOM Element: node1 at 0xed0aa8>
node2 = doc1.createElement("node2")
rt.appendChild(node2)
<DOM Element: node2 at 0xe890a8>
rt.toxml()
'<root1><node1 name="name1">the datas.</node1><node2/></root1>'
rt.childNodes
[<DOM Element: node1 at 0xed0aa8>, <DOM Element: node2 at 0xe890a8>]
node1.firstChild
<DOM Text node "the datas.">
ɾ³ý×ӽڵ㣺
n2 = rt.childNodes[1]
rt.removeChild(n2)
<DOM Element: node2 at 0xe890a8>
rt.toxml()
'<root1><node1 name="name1">the datas.</node1></root1>'
node1.removeChild(node1.firstChild)
<DOM Text
Ïà¹ØÎĵµ£º
>>> class objA:
... pass
...
>>> A = objA()
>>> B = 'a','V'
>>> B
('a', 'V')
>>> C = 'a string'
>>> print instance(A,objA)
Traceback (most recent call last):
File "<stdin>", line 1, in < ......
import pymssql
#connect database
conn=pymssql.connect(host="192.168.1.28",user="boomink",password="boomink",
database="boomink")
cur=conn.cursor()
print '========================================'
cur.execute("exec Orders_GetTest1 @Valu ......
mysqlÊÇÒ»¸öÓÅÐãµÄ¿ªÔ´Êý¾Ý¿â£¬ËüÏÖÔÚµÄÓ¦Ó÷dz£µÄ¹ã·º£¬Òò´ËºÜÓбØÒª¼òµ¥µÄ½éÉÜÒ»ÏÂÓÃpython²Ù×÷mysqlÊý¾Ý¿âµÄ·½·¨¡£python²Ù×÷Êý¾Ý¿âÐèÒª°²×°Ò»¸öµÚÈý·½µÄÄ£¿é£¬ÔÚhttp://mysql-python.sourceforge.net/
ÓÐÏÂÔØºÍÎĵµ¡£
ÓÉÓÚpythonµÄÊý¾Ý¿âÄ£¿éÓÐרÃŵÄÊý¾Ý¿âÄ£¿éµÄ¹æ·¶£¬ËùÒÔ£¬Æäʵ²»¹ÜʹÓÃÄÄÖÖÊý¾ ......
×÷Ϊһ¸ö³õѧshellµÄ³ÌÐòÔ±À´Ëµ£¬Ê¹ÓÃshellµÄһЩÃüÁîµ÷Ó㬱ÈÈç¾Íд¼¸ÐУ¬×öһЩ×Ô¶¯»¯µÄ²Ù×÷£¬¼òµ¥ÓÖʵÓ㬵«ÊÇÉæ¼°Âß¼¿ØÖƺÍ
×Ö·û´®´¦Àíʱ£¬¿´µ½ÄÇif/fi£¬case£¯esac……»¹ÓйÅÀë¹Å¹ÖµÄ²¼¶ûÅжυ…»¹Óи´ÔÓ¶øÓÖÃû×ÖºÜÏì¶øÇÒºÜÀÏ×ʸñµÄsed¡¢awk……ÎÒ¾ÍÏ룬
ÔÚûÓзÇÒªÔÚshellÖÐ ......
½ñÌìͻȻÓÐÒ»¸öÏë·¨£¬¾ÍÊÇÏë×Ô¼ºÐ´Ò»¸ö·Òë½Å±¾¡£¿ÉϧGoogleÌṩµÄAPIÊǹ©ÍøÂçÓ¦Óõġ£¸ÕºÃÔÚ¡¶dive into python¡·ÀïÃæÕâ±¾ÊéÀïÃæ¿´µ½ÈçºÎ´ÓHTMLÎĵµÖÐÌáÈ¡³öÀ´×Ô¼ºÏëÒªµÄÄÚÈÝ£¬ÄÇÕâÑùµÄ»°£¬¿É²»¿ÉÒÔÄ£Äâä¯ÀÀÆ÷À´·¢ËÍÏë·ÒëµÄ¾ä×Ó£¬È»ºóÔÙ½ÓÊÕ·µ»Ø½á¹ûºóµÄHTMLÔ´Â룬×îºó´ÓÖÐÌáÈ¡³ö·ÒëµÄ½á¹ûÄØ£¿¡¡¡¡ÆäʵÊÇÐеģ¬ÒòΪÀûÓ ......