> 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
> 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
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
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
> 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
> 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/
--
> 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/
--
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
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
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
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
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
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
> 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
>
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
> 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
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
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
>> 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.
> 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
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="")
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,
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"
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
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
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
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
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.
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
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
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
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
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"
33 matches
Mail list logo