Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 11th, 2004, 07:17 AM
munna munna is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 30 munna User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
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

Reply With Quote
  #2  
Old June 21st, 2004, 10:47 PM
jpreed00 jpreed00 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 7 jpreed00 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Python and XML -- getting element list


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT