Hello,
I don't know if you guys remember or not, but a while back I was looking
into making a "mutable navigator" interface that could be used in order to
write code that was independent of object model. I've finally got around to
working on this, with a fair degree of success so far I think, but I'm
stuck with at least one problem that I would like to ask about. This is, is
there any existing library (or even just an accepted algorithm) documented
somewhere, that allows nodes to be created based on an xpath?
Here is one example. If I have the following document:
<properties xmlns="urn:myPropsSchema">
<project name="alpha">
<frame id="001"/>
</project>
<project name="bravo">
</project>
<project name="charlie">
</project>
<properties>
Then, I would like for this following xpath:
(with 'p' mapped to "urn:myPropsSchema")
/p:properties/p:project[@name='bravo']/p:frame[@id='001']/@bounds
to add and return the new node (the bounds attribute) like this:
<properties xmlns="urn:myPropsSchema">
<project name="alpha">
<frame id="001"/>
</project>
<project name="bravo">
<frame id="001" bounds=""/> <--- bounds attribute node
returned
</project>
<project name="charlie">
</project>
<properties>
So far I've got what I *think* is a reasonable (though likely not optimal)
algorithm that repeatedly pulls off the last component (using '/' as a
delimiter of course) and repeats the evaluation, until it finds at least
one matching node. So in this case, it would be:
try 1: /p:properties/p:project[@name='bravo']/p:frame[@id='001']/@bounds
- nope
try 2: /p:properties/p:project[@name='bravo']/p:frame[@id='001'] - nope
try 3: /p:properties/p:project[@name='bravo'] - yep!
Found a hit on try 3. Then I take the remainder (in this case
p:frame[@id='001']/@bounds) and begin adding the nodes relative to the
match we found, additionally adding any qualification as necessary along
the way (for example, we add the id attribute with a value of '001' to the
frame element that we add to the bravo project).
So. My question is: is this a decent algorithm? I'm not quite as concerned
about performance as I am about robustness across the range of potential
xpaths that could be encountered. The primary use at this point is targeted
towards generating a reasonably small number of requests from a graphical
application - in the order of perhaps dozens at a time - not hundreds or
thousands in a transform server or anything (at least not yet! :).
The question is how to reasonably handle all of the weird and ambiguous
cases that can be described in an xpath? For example, //*[@name='Jim'] -
what the heck do you do with that?
Anyway thanks for any advice, or pointers to existing implementations of
this kind of functionality.
Jim
--
[EMAIL PROTECTED]
Visit www.jbrix.org for:
+ SpeedJAVA jEdit Code Completion Plugin
+ Xybrix XML Application Framework
+ other great Open Source Software
_______________________________________________________________
Don't miss the 2002 Sprint PCS Application Developer's Conference
August 25-28 in Las Vegas -- http://devcon.sprintpcs.com/adp/index.cfm
_______________________________________________
dom4j-dev mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-dev