G:\HCC\week6>dir
Volume in drive G is SWITCH
Volume Serial Number is 3187-86F2
Directory of G:\HCC\week6
12/06/2006 05:08 PM
.
12/06/2006 05:08 PM ..
12/06/2006 05:08 PM hand-in
12/06/2006 06:10 PM hand-outs
12/06/2006 06:15 PM 75 agenda.txt
12/06/2006 06:34 PM 40 attendance.txt
12/06/2006 08:21 PM 968 demo.txt
12/06/2006 06:31 PM 546 npclist.xml
12/06/2006 07:45 PM 134 output.txt
12/06/2006 09:37 PM more links
12/09/2006 01:41 PM 753 demo.py.bak
12/09/2006 01:42 PM 761 demo.py
7 File(s) 3,277 bytes
5 Dir(s) 55,255,040 bytes free
G:\HCC\week6>python
ActivePython 2.4.3 Build 12 (ActiveState Software Inc.) based on
Python 2.4.3 (#69, Apr 11 2006, 15:32:42) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import xml.dom.minidom as MD
>>> from pprint import pprint as pp
>>>
>>> doc = MD.parse('npclist.xml')
>>> doc
>>> pp(dir(doc))
['ATTRIBUTE_NODE',
'CDATA_SECTION_NODE',
'COMMENT_NODE',
'DOCUMENT_FRAGMENT_NODE',
'DOCUMENT_NODE',
'DOCUMENT_TYPE_NODE',
'ELEMENT_NODE',
'ENTITY_NODE',
'ENTITY_REFERENCE_NODE',
'NOTATION_NODE',
'PROCESSING_INSTRUCTION_NODE',
'TEXT_NODE',
'__doc__',
'__init__',
'__module__',
'__nonzero__',
'_call_user_data_handler',
'_child_node_types',
'_create_entity',
'_create_notation',
'_elem_info',
'_get_actualEncoding',
'_get_async',
'_get_childNodes',
'_get_doctype',
'_get_documentElement',
'_get_documentURI',
'_get_elem_info',
'_get_encoding',
'_get_errorHandler',
'_get_firstChild',
'_get_lastChild',
'_get_localName',
'_get_standalone',
'_get_strictErrorChecking',
'_get_version',
'_id_cache',
'_id_search_stack',
'_magic_id_count',
'_set_async',
'abort',
'actualEncoding',
'appendChild',
'async',
'attributes',
'childNodes',
'cloneNode',
'createAttribute',
'createAttributeNS',
'createCDATASection',
'createComment',
'createDocumentFragment',
'createElement',
'createElementNS',
'createProcessingInstruction',
'createTextNode',
'doctype',
'documentElement',
'documentURI',
'encoding',
'errorHandler',
'firstChild',
'getElementById',
'getElementsByTagName',
'getElementsByTagNameNS',
'getInterface',
'getUserData',
'hasChildNodes',
'implementation',
'importNode',
'insertBefore',
'isSameNode',
'isSupported',
'lastChild',
'load',
'loadXML',
'localName',
'namespaceURI',
'nextSibling',
'nodeName',
'nodeType',
'nodeValue',
'normalize',
'ownerDocument',
'parentNode',
'prefix',
'previousSibling',
'removeChild',
'renameNode',
'replaceChild',
'saveXML',
'setUserData',
'standalone',
'strictErrorChecking',
'toprettyxml',
'toxml',
'unlink',
'version',
'writexml']
>>> print doc.toxml()
>>>
>>> top = doc.documentElement
>>> top
>>> print top.toxml()
>>>
>>> children = top.childNodes
>>> children
[, , , , , , ]
>>>
>>> npc1 = children[1]
>>> npc1
>>> npc1.toxml()
u'\n \n \n '
>>> print npc1.toxml()
>>>
>>> npc1_children = npc1.childNodes
>>> npc1_children
[, , , , ]
>>>
>>> npcs = top.getElementsByTagName('npc')
>>> npcs
[, , ]
>>> npcs[0] == npc1
True
>>>
>>> npc1_items = npc1.getElementsByTagName('item')
>>> npc1_items
[, ]
>>>
>>> npc3 = npcs[2]
>>> npc3_items = npc3.getElementsByTagName('item')
>>> npc3_items
[]
>>>
>>> npc1_attrs = npc1.attributes
>>> npc1_attrs
>>> npc1_attrs.items()
[(u'y', u'42'), (u'x', u'10'), (u'mode', u'patrol'), (u'class', u'orc'), (u'name
', u'steve')]
>>> dict(npc1_attrs.items())
{u'y': u'42', u'x': u'10', u'mode': u'patrol', u'name': u'steve', u'class': u'or
c'}
>>> dict(npc1_attrs.items())[u'class']
u'orc'
>>> npc1_attrs.get('class')
>>> npc1_attrs.get('class').value
u'orc'
>>> npc1.attributes.get('class').value
u'orc'
>>> npc1.toxml()
u'\n \n \n '
>>> npc1.toxml().encode('ascii')
'\n \n \n '