473,396 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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
1 2798
bvdet
2,851 Expert Mod 2GB
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

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

Similar topics

2
by: scrimp | last post by:
Well, Ive been searching through google groups and Ive seen a lot about printing a pdf file, but I havent seen a definite answer. I tried this code: f = open(printer_path, 'w')...
4
by: dongdong | last post by:
I wrote as following: content=urllib2.urlopen("http://www.sdfagfa.org/asasg/a.zip").read() f=open("d:\\a.zip",'a+',1) f.writelines(content) the zip file has been download to my machine,but when...
16
by: baber | last post by:
Hi I am a beguinner, I would like to known how to convert a file in gpr format to csv format by using python. Baber
2
by: vinkumar | last post by:
Hi, I have to search for string and replace with user input value using js. I have used inner HTML (objExplorer.Document.body.innerHTML) to get user input. (Eg: If user inputs web port no. as...
3
by: mattmao | last post by:
Hello everyone. This question is regarding ISBN number checking. I've done it with my own algorithm, which is pretty bad in consideration about the total lines of code. Now I want to improve...
1
by: Tamer Ibrahim | last post by:
Hi, I'm trying to validate user input date using range validator on a text box . This code is throwing this exception "The value 'DateTime.Now;' of the MaximumValue property of 'rvQDate'...
3
by: askalottaqs | last post by:
could some1, please, in the simplest language possible tell me how to do this? i know the topic already exists, but im really new to python, and never done anythin with xml, i dunno what kind of...
14
by: jld730 | last post by:
All, I will have a user input a string that is either 10, 14, 17 characters long, or contains a comma (of any length). The script proceeds from there depending on the length entered. When I test...
5
by: Carlo Gambino | last post by:
I'm trying to manipulate strings of user input data, using ord() to assign the decimal value to each character in the string. I can return the values, but need to understand the best way to store the...
2
by: curien | last post by:
Hello, I am working on a code that takes the users input ( a string of digits) from the command line and prints out the median number. I am trying to accomplish this by: from sys import argv ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.