473,387 Members | 1,504 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,387 software developers and data experts.

Questions about parsing XML

I'm writing a practice program that parses an xml config file, at the
moment I'm using expat. However I don't like some of it's behaviors.
For example ParseFile() will parse the *entire* file and I don't want to
do that. I would like to be able to tell it to find such and such a tag
and return the cdata it contains, is this at all possible? If it is how
would I handle optional tags?

If it's not possible and the entire file does have to be parsed in one
fell swoop, are there any special ways collecting the data into a usable
form? I tried to put everything into a list, but that's not very
practicle, especially with optional tags.

Thanks,
Kyle
Jul 18 '05 #1
4 1339
Kyle Root <ky******@gmail.com> pisze:
I'm writing a practice program that parses an xml config file, at the
moment I'm using expat. However I don't like some of it's behaviors.
For example ParseFile() will parse the *entire* file and I don't want to
do that. I would like to be able to tell it to find such and such a tag
and return the cdata it contains, is this at all possible? If it is how
would I handle optional tags?


libxml2 (http://www.xmlsoft.org/) has excellent support for XPath, F.
Lundh's ElementTree also supports some XPath expressions, although it is
built on expat and needs to parse whole XML document.

--
Jarek Zgoda
http://jpa.berlios.de/
Jul 18 '05 #2
Jarek Zgoda wrote:


libxml2 (http://www.xmlsoft.org/) has excellent support for XPath, F.
Lundh's ElementTree also supports some XPath expressions, although it is
built on expat and needs to parse whole XML document.


Well I was going to use that, but I remember reading somewhere that
xmlib was depreciated or something, even if it has been do you still
recommend libxml2 over expat?
Jul 18 '05 #3
Kyle Root <ky******@gmail.com> pisze:
libxml2 (http://www.xmlsoft.org/) has excellent support for XPath, F.
Lundh's ElementTree also supports some XPath expressions, although it is
built on expat and needs to parse whole XML document.


Well I was going to use that, but I remember reading somewhere that
xmlib was depreciated or something, even if it has been do you still
recommend libxml2 over expat?


Python's xmllib (regular expression based parser) is not the same
software as libxml2 (GNOME XML library) ;).

If you need full support for XPath, XPointer, XInclude or namespaces
(see http://www.xml.com/pub/a/2004/06/30/py-xml.html) I recommend using
libxml2. Some people say that some of its parsers are also faster than
original J. Clark's expat (although not as easy to use as expat or
expat-like SAX parser from libxml2).

--
Jarek Zgoda
http://jpa.berlios.de/
Jul 18 '05 #4
Jarek Zgoda wrote:

Python's xmllib (regular expression based parser) is not the same
software as libxml2 (GNOME XML library) ;).

If you need full support for XPath, XPointer, XInclude or namespaces
(see http://www.xml.com/pub/a/2004/06/30/py-xml.html) I recommend using
libxml2. Some people say that some of its parsers are also faster than
original J. Clark's expat (although not as easy to use as expat or
expat-like SAX parser from libxml2).


Okay thank you very much!
I like libxml2's docs better than the Python Library Reference anyways. :D
Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Stefano | last post by:
I would like to get the value of a tag in an xml file, the problem is that, his structure is not <item>value</item> but is: <Cube> - <Cube time="somevalue"> <Cube rate="the value i want to get"...
8
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $...
2
by: BCC | last post by:
Hi, I have a small app that needs to read in an xml file that I create, and then initialize some variable and objects with the data in the file. Ive taken a look around and still cant decide...
3
by: digitalsubjunctive | last post by:
Hey, I just started on Python and have a few questions I couldn't find answers to on the Python site or it's tutorial. 1. I notice a few "compiled python" files (indicated by reddish snake...
8
by: Beatrice Rutger | last post by:
Hi, I am a previous Micro$oft desertee (moved from VB/VC++ to Java before this whole DOTNET thing) because I had several issues with Micro$oft. I am not completely in love with Windoze, but I...
21
by: Boris Ammerlaan | last post by:
This notice is posted about every week. I'll endeavor to use the same subject line so that those of you who have seen it can kill-file the subject; additionally, Supersedes: headers are used to...
0
by: James Ankrom | last post by:
Hi all, sorry I couldn't be more specific on the subject. I have a few questions that affect the design of objects I am building, and was wondering if anyone had any input or experiences to relate....
6
by: Hans Kamp | last post by:
Is it possible to write a function like the following: string ReadURL(string URL) { .... } The purpose is that it reads the URL (determined by the parameter) and returns the string in which...
0
by: Jobs | last post by:
What are the standard ways of parsing XML document? XML parser sits in between the XML document and the application who wants to use the XML document. Parser exposes set of well defined...
13
by: Chris Carlen | last post by:
Hi: Having completed enough serial driver code for a TMS320F2812 microcontroller to talk to a terminal, I am now trying different approaches to command interpretation. I have a very simple...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.