Hi,
I'm looking for a library that can search through an XML document tree,
locate an element by attribute (ideally this can be done through
XPath), and insert an element (as its child).
Simple? Yes? ...but the code I've seen so far which does this uses
'nested for loops' for trees which are relatively shallow compared to
mine. So I'm wondering if you could give me some suggestions as to
which XML library could do this without resorting to nested for loops,
and/or better yet, what's the trend in this type of operation?
Thanks in advance. 6 1289 la*********@gma il.com wrote: Hi,
I'm looking for a library that can search through an XML document tree, locate an element by attribute (ideally this can be done through XPath), and insert an element (as its child).
Try lxml: http://codespeak.net/lxml/
In [25]: from lxml import etree
In [26]: nbk = etree.parse('tu t-2.3.5-db.nbk')
In [27]: log = root.xpath('//ipython-log[@id="default-log"]')[0]
In [28]: etree.SubElemen t(log, 'cell')
Out[28]: <Element cell at d668>
--
Robert Kern rk***@ucsd.edu
"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter la*********@gma il.com wrote: Simple? Yes? ...but the code I've seen so far which does this uses 'nested for loops' for trees which are relatively shallow compared to mine. So I'm wondering if you could give me some suggestions as to which XML library could do this without resorting to nested for loops, and/or better yet, what's the trend in this type of operation?
Why do you care if they are nested for loops?
What is the problem you are experiencing that is caused
by for loops?
Does the software you've seen not work with your XML
trees? What error do you get when you try it?
Or are you just opposed to for loops on philosophical
grounds?
--
Steven.
On 7/26/05, praba kar <pr*********@ya hoo.co.in> wrote: Dear All, Can any one let me know? How to build email in python? with some some examples. regards Prabahar
The email module is what you need. http://docs.python.org/lib/module-email.html
hth :)
> Why do you care if they are nested for loops? What is the problem you are experiencing that is caused by for loops?
The nested loops which I speak of are highly dependent
on the structure of the document tree. The examples which
I've seen using DOM or ElementTree deal with shallow trees,
but in my case, I am dealing with deeper trees--which means
that the degree of nesting would also grow deeper if I were
to follow suit. Also, it makes for hard to manage code.
I'd say that lxml is exactly what I'm looking for, because
it supports XPath and Robert Kern's example is pretty reassuring.
Thanks Robert Kern!
"I'm looking for a library that can search through an XML document
tree,
locate an element by attribute (ideally this can be done through
XPath), and insert an element (as its child).
Simple? Yes? ...but the code I've seen so far which does this uses
'nested for loops' for trees which are relatively shallow compared to
mine. "
Amara can easily do this using XPath (complete with predicates,
functions, etc.), without nested for loops: http://uche.ogbuji.net/tech/4Suite/amara/
--
Uche http://uche.ogbuji.net This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Henning Kage |
last post by:
I'm writing a small Python library with some generic classes and
interfaces, that can be used within other Python projects in our company.
Would it be a better solution to compile this library into a Python DLL
(and if so, how can it be done) or to distribute the "raw" sourcecode of
these classes etc.? What would be the best solution, so that other
programmers can easily integrate this library into their own programs?
|
by: Parano |
last post by:
Is there a Python library to access CVS?
I tried to google search for it, but with "python cvs" you actually find
alot of python projects that have CVS repository...
|
by: aurora |
last post by:
Sometimes it is rather frustrated to use the Python Library Reference. It
seems each section is hand crafted and it is up to the author decide the
organization and coverage. For example the os module seems be broken down
in a somewhat abitrary way. You have to get use to it to find the way
around.
http://www.python.org/doc/2.3.4/lib/module-os.html
Some section, I would said, is more a tutorial than a reference. Most
frustrating is the...
|
by: Alessandro Bottoni |
last post by:
Which Python library would you use for developing a small Jabber client?
jabber.py (seems to be dead since 2003)
http://jabberpy.sourceforge.net/
pyxmpp (looks like the "official" python library)
http://pyxmpp.jabberstudio.org/
xmpp.py (a russian alternative. Very well documented and apparently quite
complete)
|
by: Jonathon Blake |
last post by:
All:
I thought I had seen a python library/module that easily enabled one
to read / write / create MSAccess databases a couple of years ago.
Now, I can't find it, or any reference to such a library or module.
[I used google, and the module search tools on python.
Can somebody point me to an MSAccess library/module that does that?
| |
by: bobueland |
last post by:
The "Python LIbrary Reference" at
http://docs.python.org/lib/contents.html seems to be an important
document. I have two questions
Q1. How do you search inside "Python LibraryReference" ? Does it exist
in pdf or chm form?
Q2. In some other languages (for instance PHP if I recall correctly)
readers can add comments and give examples to the various headings in
the reference manual. This gives valuable information to the reader. Is
|
by: Allerdyce.John |
last post by:
Is there a python library to parse C++ code file?
If yes, can you please tell me where is it?
Thank you.
|
by: m.n.summerfield |
last post by:
Although a fan of Python, I find the Python Library Reference page
(lib.html) very inconvenient because of its book contents-like layout.
Also, some things that seem to me to belong together, such as string
methods and string services are dispersed. Another annoyance is that
it is
so verbose: this is good for Python newbies, but frustrating once you
know
what you want to find.
So I now use a tiny Python script to read lib.html and...
|
by: Jonas |
last post by:
Quoting Christopher Lenz:
-----------------------------------------------------------------------------------------
Babel 0.8 - Jun 20, 2007
========================
We're proud to present the latest release of the Babel: 0.8.
Babel is a Python library that provides an integrated collection of
utilities that assist with internationalizing and localizing Python
applications (in particular web-based applications.)
|
by: Sengly |
last post by:
Dear all,
I am looking for a python library which can cluster similar objects
into their respective groups given their similarity score of each two
of them. I have searched the group but I couldn't find any helpful
information yet.
Any suggestion is appreciated. Also, if you know any specific group
that I should post this message, please also suggest.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |