By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,772 Members | 904 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,772 IT Pros & Developers. It's quick & easy.

how can i search xml file by user input string using DOM in Python ?

P: n/a
the xml file is like this:
Expand|Select|Wrap|Line Numbers
  1. <publist> 
  2.  <book>  
  3.    A book entry has the following fields:
  4.           o Title;
  5.           o One or more authors;
  6.           o Publisher;
  7.           o Year
  8.  </book> 
  9. <article>
  10.    An article entry has the following fields:
  11.           o Title;
  12.           o One or more authors;
  13.           o Journal title;
  14.           o Issue number;
  15.           o Range of pages;
  16.           o Year
  17. </article>
  18. </publist>
  19.  
------------------------------------------
I should provide something like this:
Search by title (t) or by author (a)?
Enter your choice: a
Write a string that the surname should contain: Moeller
Found 2:

... prints the XML contents of the book entry by Anders Moeller ...

1: Delete
2: Next item
0: Main menu
Enter your choice: 1

... prints the XML contents of the book by Sara B. Moeller ...

1: Delete
2: Next item
0: Main menu
Enter your choice: 2
Oct 26 '10 #1
Share this Question
Share on Google+
1 Reply


bvdet
Expert Mod 2.5K+
P: 2,851
I like minidom. Read in the XML file as a string and pass the string to xml.dom.minidom.parseString() to create a xml.dom.minidom.Document instance. Instance method getElementsByTagName() will return a list of elements with matching tags.

You may want to freshen up on XML basics. I like this tutorial for beginning XML.

We cannot write the code for you, so post your code and we will be glad to help.
Oct 28 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.