|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Python and XML -- getting element list
Hi,
I'm trying to find a way of getting a list of all elements and attributes allowed in an XML DTD (so that I can then compare this against an XML instance and see which of the lements/attributes are not being used). Is there a way to do this with Python and SAX? I'm a comparative newbie to Python, so would be very grateful if someone could explain how I can do this with a small code example. Thank you in advance, Munna |
|
#2
|
|||
|
|||
|
check this out
This is the module you'll want to use. It will parse the XML just like you want. SAX is used for event based XML parsing, which means that certain functions will be called based on the contents of the XML being parsed. It did not sound like this is the kind of functionality you wanted.
http://www.python.org/doc/2.3.4/lib...om.minidom.html Here's the example you wanted. This example parses a simple string. There are more examples in the link provided above, including the ability to parse an XML file. Code:
dom = parseString(""<login password="test" username="test" />")
print "Username:", dom.documentElement.getAttribute("username")
print "Password:", dom.documentElement.getAttribute("password")
print "Root Tag Name:", dom.documentElement.tagName
will return: Code:
Username: test Password: test Root Tag Name: login |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Python and XML -- getting element list |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|