Bug 261588 - [xpath] XPath View needs abilty to specify namespace prefix for Default Names
Summary: [xpath] XPath View needs abilty to specify namespace prefix for Default Names
Status: RESOLVED FIXED
Alias: None
Product: WTP Source Editing
Classification: WebTools
Component: wst.xpath (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 3.2 M5   Edit
Assignee: David Carver CLA
QA Contact: David Carver CLA
URL:
Whiteboard:
Keywords: noteworthy
Depends on:
Blocks: 297975
  Show dependency tree
 
Reported: 2009-01-19 22:25 EST by David Carver CLA
Modified: 2015-11-12 10:17 EST (History)
4 users (show)

See Also:


Attachments
First cut at adding Namespace editing for XPath View (18.60 KB, patch)
2009-12-16 18:06 EST, David Carver CLA
no flags Details | Diff
mylyn/context/zip (186.00 KB, application/octet-stream)
2009-12-17 11:39 EST, David Carver CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description David Carver CLA 2009-01-19 22:25:55 EST
XPath processors work on namespaces.   Given the following xpath expression:

/test/something

And the following XML

<test>
   <something/>
</test>

This xml file doesn't have a namespace assigned to it so it will work correctly.  However modify it to the following:

<test xmlns="http://www.example.org/">
	<something/>
</test>

The XPath expression will fail because the test element is now in a namespace.  In order to get this to work currently in the view one has to do the following:

<test xmlns="http://www.example.org/" xmlns:tns="http://www.example.org">
   <something/>
</test>

The xpath expression now created should be:

/tns:test/tns:something

This will now correctly return the results.   The user should be given an option or text entry field where the namespace can be assigned to a prefix.   The old XPath Navigator View had this functionality, so we may want to migrate that functionality into the current XPath view.

User documenation should also be written so that it is clear how the use the XPath view when a namespace is encountered within the xml file.
Comment 1 David Carver CLA 2009-03-06 21:17:07 EST
We'll need to revisit this during 1.1 M1 after galileo.
Comment 2 David Carver CLA 2009-09-02 15:24:22 EDT
Assigning inbox items to triaged since these have all be triaged.
Comment 3 David Carver CLA 2009-12-16 18:06:50 EST
Created attachment 154610 [details]
First cut at adding Namespace editing for XPath View

This is a first cut at enabling namespaces to be set for the XPath view.
Comment 4 David Carver CLA 2009-12-16 19:03:12 EST
The basic steps to this were to merge in the namespace functionality from the old XPathNavigator and apply it to the current XPathView.   Right now there is a button i the view to bring up a dialog to allow entering/updating the existing namespaces.   This probably should be added as either a View Toolbar item or a View Menu item to help keep the view clean.
Comment 5 David Carver CLA 2009-12-17 11:39:19 EST
Created attachment 154676 [details]
mylyn/context/zip

Context for XPath Namespace prefix editing on XPath view.
Comment 6 David Carver CLA 2009-12-17 11:43:36 EST
This is now working.  The changes that were made were to remove the edit prefixes button, created a View Menu item for the XPath view.  Added a Edit Namespace Prefixes menu option.  Created a command and handler for the action (adopters can provide their own handler implementation if desired).  I also set the hashmap to use a ConcurrentHashMap instead of a WeakHashMap, as well as changed the Namespec look up information in the hashmap to be based on the modelID instead of keying on the org.w3c.dom.Document interface class.  This was holding a copy of the entire model in memory when it was unnecessary.

This did uncover a couple of WTP DOM methods that need to be implemented so I can get away from the modelID, getBaseURI and getDocumentURI.  I'll open separate issues for those and hopefully supply a patch and unit tests for it.
Comment 7 Juergen Weber CLA 2015-11-12 05:07:46 EST
Given an ejb-jar.xml like

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar id="ejb-jar_ID" version="2.1"
	xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd">
	<display-name>MyMDB</display-name>
	<enterprise-beans>
		<message-driven>
			<ejb-name>MyMDB</ejb-name>

If you add a jee namespace prefix for the target namespace http://java.sun.com/xml/ns/j2ee
you can evaluate expressions like

/jee:ejb-jar[1]/jee:display-name/

This is not intuitive, why should I have to add a prefix in the xpath expression if I don't have to in the xml?
This should work just like


/ejb-jar[1]/display-name/
Comment 8 Jesper Moller CLA 2015-11-12 08:47:16 EST
@Jürgen:

While I certainly understand your irritation with this, the real problem is a quirk in the XPath specification, not in the WTP Path view. Actually, the XPath View does provide the non-prefixed namespace to the XPath processor, but it won't help.

There is a good explanation here:

http://stackoverflow.com/questions/10981312/xml-element-has-namespace-my-xpath-does-not-work
Comment 9 Jesper Moller CLA 2015-11-12 10:17:18 EST
Also /*:ejb-jar[1]/*:display-name/ should work.