Re: [dom4j-user] xpath problem

2009-04-16 Thread Ozakca, Muzaffer
Try this as I don’t know how to do what you’re trying to do using that simpler 
code:

Map m = new HashMap();
m.put(“html”, “http://www.w3.org/1999/xhtml“);
Xpath xpath = DocumentHelper.createXPath(“//html:meta”);
xpath.setNamespaceURIs(m);
Element metaElem = (Element) xpath.selectSingleNode(document);

I think this will retrieve the first “meta” node.
Muzaffer

From: matt.rossner-pr...@sanofi-aventis.com 
[mailto:matt.rossner-pr...@sanofi-aventis.com]
Sent: Thursday, April 16, 2009 11:35 AM
To: dom4j-user@lists.sourceforge.net
Subject: Re: [dom4j-user] xpath problem

Well it’s an HTML document. It does have an xmlns declaration, although it’s 
been a while since I’ve done any XML so I don’t remember exactly what that 
does. But the elements themselves, like  don’t have any namespace 
prefixed to them.

The xmlns declaration is:

http://www.w3.org/1999/xhtml"; lang="fr">

Thanks for your help


From: Linus Kamb [mailto:li...@iris.washington.edu]
Sent: jeudi 16 avril 2009 17:29
To: Rossner, Matt PH/FR/PREST
Subject: Re: [dom4j-user] xpath problem

namespace?

matt.rossner-pr...@sanofi-aventis.com<mailto:matt.rossner-pr...@sanofi-aventis.com>
 wrote:
Hello,

I’m having an issue with a very simple Xpath expression. I don’t quite 
understand why this fails. Probably missing something obvious. This is just a 
simple example:

SAXReader r = new SAXReader();
try {
Document document = r.read(new File("c:\\file.xml"));

Element metaEle = (Element) document.selectSingleNode("//meta");

} catch (Exception e) {
e.printStackTrace();
}

Now « file.xml » definitely has a meta element but this always returns null. 
I’ve tried also selectNodes to see if that makes any difference. I tried with a 
bunch of other tags but they all fail unless if I put in the root tag. If I’m 
not mistaken though “//meta” should return all meta elements in the document??? 
Thanks for any help with this.

Matt
























--

Stay on top of everything new and different, both inside and

around Java (TM) technology - register by April 22, and save

$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.

300 plus technical and hands-on sessions. Register today.

Use priority code J9JMT32. http://p.sf.net/sfu/p





















___

dom4j-user mailing list

dom4j-user@lists.sourceforge.net<mailto:dom4j-user@lists.sourceforge.net>

https://lists.sourceforge.net/lists/listinfo/dom4j-user


--
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p___
dom4j-user mailing list
dom4j-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dom4j-user


Re: [dom4j-user] xpath problem

2009-04-16 Thread Matt.Rossner-prest
Well it's an HTML document. It does have an xmlns declaration, although
it's been a while since I've done any XML so I don't remember exactly
what that does. But the elements themselves, like  don't have any
namespace prefixed to them.

 

The xmlns declaration is:

 

http://www.w3.org/1999/xhtml"; lang="fr">

 

Thanks for your help

 



From: Linus Kamb [mailto:li...@iris.washington.edu] 
Sent: jeudi 16 avril 2009 17:29
To: Rossner, Matt PH/FR/PREST
Subject: Re: [dom4j-user] xpath problem

 

namespace?

matt.rossner-pr...@sanofi-aventis.com wrote: 

Hello,

 

I'm having an issue with a very simple Xpath expression. I don't quite
understand why this fails. Probably missing something obvious. This is
just a simple example:

 

SAXReader r = new SAXReader();

try {

Document document = r.read(new File("c:\\file.xml"));



Element metaEle = (Element)
document.selectSingleNode("//meta");



} catch (Exception e) {

e.printStackTrace();

}

 

Now < file.xml > definitely has a meta element but this always returns
null. I've tried also selectNodes to see if that makes any difference. I
tried with a bunch of other tags but they all fail unless if I put in
the root tag. If I'm not mistaken though "//meta" should return all meta
elements in the document??? Thanks for any help with this.

 

Matt

 

 

 

 







 

--
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p
 







 
___
dom4j-user mailing list
dom4j-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dom4j-user
  
--
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p___
dom4j-user mailing list
dom4j-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dom4j-user


Re: [dom4j-user] XPath problem

2007-08-10 Thread Ozakca, Muzaffer
I wish I was clever and did some research first. I found the answer in the list 
archives:

I should have done:

code ---
Map map = new HashMap();
map.put("result", "http://www.w3.org/2001/sw/DataAccess/rf1/result";);

XPath xpath = DocumentHelper.createXPath("//result:k0");
xpath.setNamespaceContext(new SimpleNamespaceContext(map));

Node sizeNode = xpath.selectSingleNode(sizeDoc);
--- code

As suggested by Edwin. Thanks anyways,
m

-
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
___
dom4j-user mailing list
dom4j-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dom4j-user


Re: [dom4j-user] XPath problem with *

2005-01-29 Thread Edwin Dankert
> The XML is already as you stated it needed to be (i.e.
> it uses '<' rather than '<').  Since the XPath
> expression is not part of an XML document (e.g. an XSL
> Stylesheet), I don't believe that it needs to be
> escaped in the String that is the parameter to the
> XPath constructor.  In fact, it does not work if it is
> escaped.

I'm sorry that seems to be a problem with GMail...

You're right, this seems to depend on the way the XPath 
is processed (they should really be interchangeable).

> I did make the change to the program to include the
> first xqx:expr prior to the '*' and the program runs
> successfully.  Thanks for that advice.
>
> However, I have a follow-up question.  Why is the
> first xqx:expr needed in the XPath expression?
> Shouldn't the '*' match the first xqx:expr and its
> descendents?  I am very confused by this.  Doesn't
> this seem like a bug in DOM4J's XPath expression
> evaluation?

'*' is used to match all child elements of the current node, 
you could however have used '//' to match all descendants.

So you could write your xpath like this:
/rr:ReportRequest//xqx:[EMAIL PROTECTED]:type ...

Hope this helped,
Edwin


---
This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting
Tool for open source databases. Create drag-&-drop reports. Save time
by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc.
Download a FREE copy at http://www.intelliview.com/go/osdn_nl
___
dom4j-user mailing list
dom4j-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dom4j-user


Re: [dom4j-user] XPath problem with *

2005-01-29 Thread David P. Nesbitt
Edwin,

Thanks very much for your response.

The XML is already as you stated it needed to be (i.e.
it uses '<' rather than '<').  Since the XPath
expression is not part of an XML document (e.g. an XSL
Stylesheet), I don't believe that it needs to be
escaped in the String that is the parameter to the
XPath constructor.  In fact, it does not work if it is
escaped.

I did make the change to the program to include the
first xqx:expr prior to the '*' and the program runs
successfully.  Thanks for that advice.

However, I have a follow-up question.  Why is the
first xqx:expr needed in the XPath expression? 
Shouldn't the '*' match the first xqx:expr and its
descendents?  I am very confused by this.  Doesn't
this seem like a bug in DOM4J's XPath expression
evaluation?

Regards,
Dave

--- Edwin Dankert <[EMAIL PROTECTED]> wrote:

> I can see one problem with your XML and another
> problem 
> with your XPath.
> 
> The problem with your XML is caused by the '<'
> character 
> used as XML content.
> 
> > <=
> 
> This is not well-formed XML, it should be:
> 
> <=
> 
> Did this throw an exception?
> 
> The XPath is wrong because, it does first of all not
> specify 
> the element you want, (you forgot to include the
> first xqx:expr 
> element) and secondly you will have to include the
> XML 
> content change above in the XPath.
> 
> > /rr:ReportRequest/xqx:whereClause/*/xqx:expr
> > [EMAIL PROTECTED]:type = 'operatorExpr' 
> > and xqx:opType = '<=' 
> > and xqx:parameters/xqx:expr[1]/xqx:value =
> 'DateMisplaced']
> > /xqx:parameters/xqx:expr[2]/xqx:value
> 
> So your XPath should be:
> 
>
/rr:ReportRequest/xqx:whereClause/xqx:expr/*/xqx:expr
> [EMAIL PROTECTED]:type = 'operatorExpr' and xqx:opType = '<='
> 
> and xqx:parameters/xqx:expr[1]/xqx:value =
> DateMisplaced']
> /xqx:parameters/xqx:expr[2]/xqx:value
> 
> Regards,
> Edwin
> 
> 
>
---
> This SF.Net email is sponsored by: IntelliVIEW --
> Interactive Reporting
> Tool for open source databases. Create drag-&-drop
> reports. Save time
> by over 75%! Publish reports on the web. Export to
> DOC, XLS, RTF, etc.
> Download a FREE copy at
> http://www.intelliview.com/go/osdn_nl
> ___
> dom4j-user mailing list
> dom4j-user@lists.sourceforge.net
>
https://lists.sourceforge.net/lists/listinfo/dom4j-user
> 




__ 
Do you Yahoo!? 
Take Yahoo! Mail with you! Get it on your mobile phone. 
http://mobile.yahoo.com/maildemo 


---
This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting
Tool for open source databases. Create drag-&-drop reports. Save time
by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc.
Download a FREE copy at http://www.intelliview.com/go/osdn_nl
___
dom4j-user mailing list
dom4j-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dom4j-user


Re: [dom4j-user] XPath problem with *

2005-01-29 Thread Edwin Dankert
I can see one problem with your XML and another problem 
with your XPath.

The problem with your XML is caused by the '<' character 
used as XML content.

> <=

This is not well-formed XML, it should be:

<=

Did this throw an exception?

The XPath is wrong because, it does first of all not specify 
the element you want, (you forgot to include the first xqx:expr 
element) and secondly you will have to include the XML 
content change above in the XPath.

> /rr:ReportRequest/xqx:whereClause/*/xqx:expr
> [EMAIL PROTECTED]:type = 'operatorExpr' 
> and xqx:opType = '<=' 
> and xqx:parameters/xqx:expr[1]/xqx:value = 'DateMisplaced']
> /xqx:parameters/xqx:expr[2]/xqx:value

So your XPath should be:

/rr:ReportRequest/xqx:whereClause/xqx:expr/*/xqx:expr
[EMAIL PROTECTED]:type = 'operatorExpr' and xqx:opType = '<=' 
and xqx:parameters/xqx:expr[1]/xqx:value = DateMisplaced']
/xqx:parameters/xqx:expr[2]/xqx:value

Regards,
Edwin


---
This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting
Tool for open source databases. Create drag-&-drop reports. Save time
by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc.
Download a FREE copy at http://www.intelliview.com/go/osdn_nl
___
dom4j-user mailing list
dom4j-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dom4j-user


Re: [dom4j-user] xpath problem, a clue to the problem.

2001-12-11 Thread James Strachan

Do you have a sample XHTML document that reproduces the problem. I've tried
writing a test case using the example you gave but it works fine for me. Its
included below...

The exception you're getting does look like an old version of Jaxen. Could
it be? I've tested this against the daily build and 1.0 of dom4j and it
appears to work fine.

James

public void testRobLebowitz() throws Exception {
String text = ""
+ ""
+ ""
+ ""
+ ""
+ ""
+ ""
+ ""
+ "";

Document document = DocumentHelper.parseText( text );
List lists = document.selectNodes( "//ul | //ol" );

int count = 0;
for (int i = 0; i < lists.size(); i++) {
Element list = (Element)lists.get(i);
List nodes = list.selectNodes("ancestor::ul");
if ((nodes != null) && (nodes.size() > 0)) {
continue;
}
nodes = list.selectNodes("ancestor::ol");
if ((nodes != null) && (nodes.size() > 0)) {
continue;
}
}
}

- Original Message -----
From: "Robert J. Lebowitz" <[EMAIL PROTECTED]>
To: "Brain, Jim" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Friday, December 07, 2001 10:58 PM
Subject: Re: [dom4j-user] xpath problem, a clue to the problem.


> Actually, after "fixing" the html, I still continue to have the problem of
> the null pointer exception.  I can't figure out what is causing it.  In
the
> interim, I just wrapped the code that throws the exception with a
try/catch
> clause and ignore the exception.
>
> I'm still a bit puzzled about how to rename elements however.  As far as I
> can tell from the API, there are some situations where a node is
read-only,
> and you  can't modify it's contents.
>
> As near as I can tell, you are forced to create a new document, and stick
in
> the nodes you want in their appropriate locations if you want to rename
> them.  With large documents this is prohibitively difficult I'm
curious
> why the setName() method can't be used.
>
>
>
>
> ___
> dom4j-user mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/dom4j-user
>


_
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


___
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user



Re: [dom4j-user] xpath problem, a clue to the problem.

2001-12-07 Thread Robert J. Lebowitz

Actually, after "fixing" the html, I still continue to have the problem of
the null pointer exception.  I can't figure out what is causing it.  In the
interim, I just wrapped the code that throws the exception with a try/catch
clause and ignore the exception.

I'm still a bit puzzled about how to rename elements however.  As far as I
can tell from the API, there are some situations where a node is read-only,
and you  can't modify it's contents.

As near as I can tell, you are forced to create a new document, and stick in
the nodes you want in their appropriate locations if you want to rename
them.  With large documents this is prohibitively difficult I'm curious
why the setName() method can't be used.




___
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user



RE: [dom4j-user] xpath problem, a clue to the problem.

2001-12-07 Thread Brain, Jim

In HTML, you should never have two ul's together, I think it should be:













However, that's just an FYI, I doubt that is the problem here.

Jim



Jim Brain, [EMAIL PROTECTED]
"Researching tomorrow's decisions today."
(319) 369-2070 (work)
SYSTEMS ARCHITECT, INDIVIDUAL ITS, LIFE INVESTORS INSURANCE COMPANY OF
AMERICA

 -Original Message-
From:   Robert J. Lebowitz [mailto:[EMAIL PROTECTED]] 
Sent:   Friday, December 07, 2001 10:09 AM
To: [EMAIL PROTECTED]
Subject:[dom4j-user] xpath problem, a clue to the problem.

I think I've figured out the source of the error, but I think it may be
prudent to modify dom4j to adjust for such a circumstance:

The author of the HTML document that I am converting to XHTML with JTidy,
and then modifying with dom4j included an embedded unordered list that
worked in the following manner:











This results in a double indentation of the text in the document.  It seems
a bit odd to do this, but I suppose it occassionally occurs in other
documents as well.

Anyhow, when I attempt to use an xpath expression like "ancestor::ul" on a
 element as I showed in my example, I end up with a null pointer
exception for this embedded list.  I'm assuming that the expression parser
becomes confused by the fact that the parent element is the same as the
child (which admittedly is a bit odd).

Does this make sense, James

Rob


___
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user

___
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user