Re: [dom4j-user] Problem with selectSingleNode() when xml tree contains xmlns attribute

2007-01-23 Thread Edwin Dankert
> I found something interesting. Doesn't look like w3c agrees with me > about nodes inheriting namespace changes. > > http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/namespaces-algorithms.html#conflicting This describes a limitation of DOM, this does not have to be a limitation to dom4j o

Re: [dom4j-user] Problem with selectSingleNode() when xml tree contains xmlns attribute

2007-01-23 Thread Edwin Dankert
> You may want to look into using Apache's xerces/xalan implementation of > DOM/XPath. I had no problems running normal XPath expressions such as > "/html/body/[EMAIL PROTECTED]'content']" against an XHTML document. The code > for running XPath is much less convenient though... I also had > seri

Re: [dom4j-user] Problem with selectSingleNode() when xml tree contains xmlns attribute

2007-01-22 Thread Evan Kirkconnell
You may want to look into using Apache's xerces/xalan implementation of DOM/XPath. I had no problems running normal XPath expressions such as "/html/body/[EMAIL PROTECTED]'content']" against an XHTML document. The code for running XPath is much less convenient though... I also had serializat

Re: [dom4j-user] Problem with selectSingleNode() when xml tree contains xmlns attribute

2007-01-22 Thread Evan Kirkconnell
I found something interesting. Doesn't look like w3c agrees with me about nodes inheriting namespace changes. http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/namespaces-algorithms.html#conflicting --Evan Evan Kirkconnell wrote: > I complete disagree and believe that there a big misi

Re: [dom4j-user] Problem with selectSingleNode() when xml tree contains xmlns attribute

2007-01-21 Thread Edwin Dankert
> I do think this affects portability, but are you suggesting that we use > xpath such as: > //http://www.w3.org/1999/xhtml:html/http://www.w3.org/1999/xhtml:body/http://www.w3.org/1999/xhtml:a > ? > I'm not even sure this is the right syntax, because you would probably > have to escape the colon a

Re: [dom4j-user] Problem with selectSingleNode() when xml tree contains xmlns attribute

2007-01-20 Thread Edwin Dankert
> Is there such a thing in dom4j? I am asking since I > am still fairly new to dom4j and maybe the dom4j > experts could let me know. I agree that something like this might be very handy functionality but there is currently no such option in dom4j. Regards, Edwin -- http://www.edankert.com/ --

Re: [dom4j-user] Problem with selectSingleNode() when xml tree contains xmlns attribute

2007-01-20 Thread Edwin Dankert
> I came up with an alternative that seems to work for > my situation: That is a very creative solution for this problem. (I didn't even realise that you could map the prefix to an empty namespace uri) Regards, Edwin -- http://www.edankert.com/ --

Re: [dom4j-user] Problem with selectSingleNode() when xml tree contains xmlns attribute

2007-01-19 Thread S. Sharif
Yes, I agree. I am converting a non-Java application to Java in which XPath was used quite extensively in the code. In the old non-Java language the XPath worked just fine without using namespace prefixes. It would be nice if I could use those XPath expressions as is, without going through the

Re: [dom4j-user] Problem with selectSingleNode() when xml tree contains xmlns attribute

2007-01-19 Thread Evan Kirkconnell
Yeah, I did something similar for a while. The XPath is still ugly IMO. You may be surprised at how fast dom4j can strip them. I did some tests to see if it was viable, and I think it was only like 10 milliseconds for a decent size document. It was a long time ago though... --Evan S. Sharif

Re: [dom4j-user] Problem with selectSingleNode() when xml tree contains xmlns attribute

2007-01-19 Thread S. Sharif
Thanks for the code. But that might not be too efficient for large xml documents, since there would be a lot of looping for large xml documents. I came up with an alternative that seems to work for my situation: // Get the namespace uri for inputDocument xml document if any String namespaceURI

Re: [dom4j-user] Problem with selectSingleNode() when xml tree contains xmlns attribute

2007-01-19 Thread Evan Kirkconnell
Have you not read our ongoing debate? It's very related. :-) Basically, the answer is 'no', but I think it should be 'yes'. If you're bold enough to remove the namespaces, take a look at code here: http://www.mail-archive.com/dom4j-user%40lists.sourceforge.net/msg02511.html --Evan S. Shari

Re: [dom4j-user] Problem with selectSingleNode() when xml tree contains xmlns attribute

2007-01-19 Thread S. Sharif
Sorry, please ignore my previous e-mail. You already provided the correct solution. I tried it and it works. One more last question. Is it always necessary to specify the namespace in order for the XPath to work? Is there a way for me to ignore the namespace and just have the XPath work witho

Re: [dom4j-user] Problem with selectSingleNode() when xml tree contains xmlns attribute

2007-01-19 Thread Evan Kirkconnell
Edwin Dankert wrote: >> A better example of what I find weird would be that if you have an >> entire document that is in the xhtml namespace and then one node that is >> in the "" namespace, then any, 'normal' xpath expressions.(ones without >> namespace specification. eg: //[EMAIL PROTECTED]'blah

Re: [dom4j-user] Problem with selectSingleNode() when xml tree contains xmlns attribute

2007-01-19 Thread Edwin Dankert
> A better example of what I find weird would be that if you have an > entire document that is in the xhtml namespace and then one node that is > in the "" namespace, then any, 'normal' xpath expressions.(ones without > namespace specification. eg: //[EMAIL PROTECTED]'blah'] would ONLY consider >

Re: [dom4j-user] Problem with selectSingleNode() when xml tree contains xmlns attribute

2007-01-19 Thread Evan Kirkconnell
Edwin Dankert wrote: >> I think you misunderstand what I'm saying. I'm saying that if the >> context node from either of your examples is the node named 'root'(or >> 'test:root'), for an XPath expression 'child', that the default >> namespace for the XPath expression would be "urn:blah.com:blah" i

Re: [dom4j-user] Problem with selectSingleNode() when xml tree contains xmlns attribute

2007-01-19 Thread Edwin Dankert
> I think you misunderstand what I'm saying. I'm saying that if the > context node from either of your examples is the node named 'root'(or > 'test:root'), for an XPath expression 'child', that the default > namespace for the XPath expression would be "urn:blah.com:blah" instead > of "" and that i

Re: [dom4j-user] Problem with selectSingleNode() when xml tree contains xmlns attribute

2007-01-18 Thread S. Sharif
One more thing, the NullPointerException is not caused by a JaxenException being thrown from inside the getXmlElementUsingXPath() method that I defind. Because the catch block is not called when I run the code. > catch (JaxenException e) > { > System.err.println("Trouble with Jax

Re: [dom4j-user] Problem with selectSingleNode() when xml tree contains xmlns attribute

2007-01-18 Thread S. Sharif
Hi, I tried what you suggested but it still does not seem to work for me. I get a NullPointerException on the line of code that calls getXmlElementUsingXPath() String xpath = "Document/[EMAIL PROTECTED]'Primary']/LOGIN/USERID"; String primaryUserId = getXmlElementUsingXPath(inputDocument, xpat

Re: [dom4j-user] Problem with selectSingleNode() when xml tree contains xmlns attribute

2007-01-18 Thread Evan Kirkconnell
>> I also believe that the Jaxen has made the same misinterpretation which >> led to the implementation assuming the empty namespace when no namespace >> is specified. As much as I wish the XPath docs stated what the default >> namespace for XPath processing should be, I haven't found anything.

Re: [dom4j-user] Problem with selectSingleNode() when xml tree contains xmlns attribute

2007-01-18 Thread Edwin Dankert
> So, logically its children. Therefore, its children should be dependent on it > supplying this default namespace. If it were to no longer supply this > default namespace, then the children would logically default to the > xhtml namespace. Also, if you were to take this XML document and change

Re: [dom4j-user] Problem with selectSingleNode() when xml tree contains xmlns attribute

2007-01-18 Thread Evan Kirkconnell
I complete disagree and believe that there a big misinterpretations here leading to poor implementation and massive confusion. The misinterpretation that I've seen stated in many places and by Richard Eckart earlier in this thread is: XPath statement operates on the default namespace (xmlns="")

Re: [dom4j-user] Problem with selectSingleNode() when xml tree contains xmlns attribute

2007-01-18 Thread Edwin Dankert
Attributes always need to be specifically declared in a namespace. "If there is a default namespace declaration in scope, the expanded name corresponding to an unprefixed element name has the URI of the default namespace as its namespace name. If there is no default namespace declaration in scope,

Re: [dom4j-user] Problem with selectSingleNode() when xml tree contains xmlns attribute

2007-01-18 Thread Richard Eckart
Hi Edwin, will this work? When the default namespace is set on a document, wouldn't it also apply to all attributes? Wouldn't it be necessary to use "@we:filter" as well? Regards, Richard >XPath xpath = new > Dom4jXPath("we:Document/we:[EMAIL PROTECTED]'Primary']/we:LOGIN/ > we:USERID"

Re: [dom4j-user] Problem with selectSingleNode() when xml tree contains xmlns attribute

2007-01-18 Thread Richard Eckart
Hi, that is because your XPath statement operates on the default namespace (xmlns="") and when you set a different default namespace in your document the query will yield "null" as a result of the selectSingleNode method and your getText() will not work on null. Note that I only tried the f

Re: [dom4j-user] Problem with selectSingleNode() when xml tree contains xmlns attribute

2007-01-18 Thread Edwin Dankert
This doesn't work, instead you will have to define a prefix for the namespace, it does not matter that the prefix in you code does not match the one in the XML document (actually the code wouldn't be very portable if this had to be case)! > try { > HashMap map = new HashMap(); > // usually I p

Re: [dom4j-user] Problem with selectSingleNode() when xml tree contains xmlns attribute

2007-01-18 Thread Richard Eckart
Hi, that is because your XPath statement operates on the default namespace (xmlns="") and when you set a different default namespace in your document the query will yield "null" as a result of the selectSingleNode method and your getText() will not work on null. Note that I only tried the f

Re: [dom4j-user] Problem with selectSingleNode() when xml tree contains xmlns attribute

2007-01-18 Thread Edwin Dankert
This is caused by you using a default namespace. Please have a look at the following threads for the answer: http://www.mail-archive.com/dom4j-user%40lists.sourceforge.net/msg02510.html http://www.mail-archive.com/dom4j-user%40lists.sourceforge.net/msg02346.html Regards, Edwin -- http://www.edan

Re: [dom4j-user] Problem with selectSingleNode() when xml tree contains xmlns attribute

2007-01-18 Thread Edwin Dankert
Please see for more information: http://www.mail-archive.com/dom4j-user%40lists.sourceforge.net/msg02450.html Regards, Edwin -- http://www.edankert.com/ - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.

[dom4j-user] Problem with selectSingleNode() when xml tree contains xmlns attribute

2007-01-17 Thread S. Sharif
Hi, The following piece of code works fine primaryUserId = inputDocument.selectSingleNode("Document/[EMAIL PROTECTED]'Primary']/LOGIN/USERID").getText(); for the following xml tree testuser somepassword But when the above xml tree is modified by adding

[dom4j-user] Problem with selectSingleNode() when xml tree contains xmlns attribute

2007-01-17 Thread S. Sharif
Hi, The following piece of code works fine primaryUserId = inputDocument.selectSingleNode("Document/[EMAIL PROTECTED]'Primary']/LOGIN/USERID").getText(); for the following xml tree testuser somepassword But when the above xml tree is modified by ad

Re: [dom4j-user] Problem with selectSingleNode

2003-08-15 Thread David D. Lucas
As Christian put it, use the elementText("name") to get the child element "name" from the car. But looking just at you XPath, you are at the current element "." which is already named "car", so there is no children named "car" below this one. Only the element "name" is available. selectN

Re: [dom4j-user] Problem with selectSingleNode

2003-08-15 Thread Christian Niles
Unless I'm missing some detail, I believe your problem lies with the XPath expression you're using: Element name = (Element) car.selectSingleNode("./car/name"); you have a car element, and the xpath says "select the name element, of each car child element within the given car". Which would m

[dom4j-user] Problem with selectSingleNode

2003-08-15 Thread emiliano carlesi
Hi, I'm new of this list, and this is my first message on it. I have a problem with XPath (I think). I have the following code : import org.dom4j.*; import org.dom4j.xpath.*; import java.util.*; public class TDOM { public static void main(String[] args) { String xml = ""; xml += "BMW M3rear"