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

DOM / XPath combination

Hi all,

Here is a little concept problem, and I need some guideline. I am
currently developing a application which delivers XML files. I want
then to sequentially perform some actions on selected part of that XML
file through a XPath expression. These action have actually to modify
the structure of the XML file itself and that seems to me like a big
hurdle. Maybe I am wrong but I will try to explain what I want to
do...

the XML file ressembles that... very roughly :)

<Root>
<Obj1>
<Head action="yes">blah</Head>
<Body>blah</Body>
<Foot action="yes">blah</Foot>
</Obj1>
...
<Obj2>
<Head>blah</Head>
<Body action="yes">blah</Body>
<Foot>blah</Foot>
</Obj2>
</Root>

let say my XPath expression is '//*[@action="yes"]'. Now for each of
the 3 concerned element I want to do some formatting...

<Root>
<Obj1>
<Head action="yes">
<bonus>yo</bonus> <--- added as part of the formatting
<text>blah<text> <--- formatting
</Head>
<Body>blah</Body>
<Foot action="yes">
<text>blah<text> <--- formatting
<bonus>yo</bonus> <--- added as part of the formatting
</Foot>
</Obj1>
...
<Obj2>
<Head>blah</Head>
<Body action="yes">
<text>blah<text> <--- formatting
</Body>
<Foot>blah</Foot>
</Obj2>
</Root>

Here is my problem. I first convert my XML file to a DOM
representation, in order to be able to do sequential processing.
Indeed a mere XSLT transfo is of no help since I want to be able to do
many thing between two actions. I then do the XPath evaluation but
further modification of the resulting nodelist will never be reflected
in the original XML files. I should say that I am using python 2.3,
and Domlette/XPath from 4suite to do that.

My question is:

How can I use the resulting XPath result as a live representation of
the underlying XML nodes (DOM concept) so that I can both perform
sequential action (by traversing the resulting xpath nodelist) and
reflects modifications done on those same nodes in the original XML
file?

Maybe I am wrong on the live object concept of the DOM but I thought
it would be possible. Any idea to achieve that would be welcome...

Phoebian
Jul 20 '05 #1
1 1636
ph******@free.fr (Phoebian) wrote in message news:<57**************************@posting.google. com>...
How can I use the resulting XPath result as a live representation of
the underlying XML nodes (DOM concept) so that I can both perform
sequential action (by traversing the resulting xpath nodelist) and
reflects modifications done on those same nodes in the original XML
file?

Maybe I am wrong on the live object concept of the DOM but I thought
it would be possible. Any idea to achieve that would be welcome...


Actually, the results of 4XPath node set expressions are lists of
actual Domlette nodes, and you can use the mutation API on these
nodes. For the API see:

http://uche.ogbuji.net/tech/akara/no...1-01/domlettes

You can then use Domlette.Print(node) to reflect the updates back to
XML.

Did you try any particular mutations with no effect (or ill effect)?

FWIW, you might want to consider XUpdate, which is also implemented in
4Suite. I happen to cover it in my most recent ORA article:

http://www.xml.com/pub/a/2004/05/12/py-xml.html

--Uche
http://uche.ogbuji.net
Jul 20 '05 #2

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

Similar topics

1
by: bdinmstig | last post by:
I refined my attempt a little further, and the following code does seem to work, however it has 2 major problems: 1. Very limited support for XPath features Basic paths are supported for...
0
by: KathyB | last post by:
Hi, I'm trying to get the @order attribute of the <WI> element for the LAST WI element for the Board element as specified. I've tried every combination I can think of, but I'm not getting any node...
1
by: Rob | last post by:
Hi, I am moving through an XML document using an XPath Navigator, and I'd like to be able to get the xpath expression for the location of the current node from the root node. Any ideas how to...
10
by: Michael C# | last post by:
OK, here's the deal. I have a small XML file that represents a small database table. I load it into a System.XML.XMLDocument. So far so good. I run an XPath query against it to retrieve all the...
3
by: Stefan Behnel | last post by:
Hi! I need to generate source code (mainly Java) from a domain specific XML language, preferably from within a Python environment (since that's where the XML is generated). I tried using...
0
by: jacqueharper | last post by:
I am having a problem with an Excel ListObject in my C# .NET application. I am trying to map an XML schema to a ListObject, and continue to get the error "The XPath is not valid because either the...
4
by: ziggyware | last post by:
Hi All, I've been writing an XPath genration tool in .NET that has GREAT potential for business applications where exact XPaths are needed. Currently the tool is share ware however it can be...
8
by: sehiser | last post by:
Hello, I've been reading up on xpath and I am able to access elements with it. I haven't been able to figure one thing out though. How would I use XPath to select an element where the text...
1
by: ranadhirnag | last post by:
We are trying to enforce a couple of business constrainrs with XPATH . A sample xml node is as follows: ..... ..... <event> <element>IE</element> <elementtype>browser</elementtype>...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.