Re: [dom4j-user] JTidy-Dom4j-NullPointerException

2003-06-02 Thread Marco Pöhler
That works !

and with the namespace hint I configured Jtidy not to create a valid XML 
[setXmlOut(true)] instead of XHTML [setXHTML(true)]. Then JTidy doesn't 
create namespaces and /html/body/table works fine, also.

Thank you, Dave !

Marco


 You have a default namespace defined in the root.

   .append(html xmlns=\http://www.w3.org/1999/xhtml\;)

 You may want to use the /*[local-name()='html']/*[local-name()='body']
 to avoid the namespace all together.

 Give that a try.



---
This SF.net email is sponsored by: eBay
Get office equipment for less on eBay!
http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5
___
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user


[dom4j-user] JTidy-Dom4j-NullPointerException

2003-05-31 Thread Marco Phler
Hi,

I want to use XPath Expressions on a HTML page. I use
JTidy to convert a page into XHTML. This XHTML can be 
easily transformed into a dom4j Document. 
My current problem is that I get a NullPointerException 
if I try to access any Node in the page using a XPath
Expression. I don't understand why...

Thanks in advance

Marco

%---
import java.io.ByteArrayInputStream;
import java.io.InputStream;

import org.dom4j.Document;
import org.dom4j.Node;
import org.dom4j.io.DOMReader;
import org.w3c.tidy.Tidy;

public class TestTidyDom4j
{
public static void main(String[] args)
{
String page=
new StringBuffer()
.append(html)
.append(head)
.append(title)
.append(Test)
.append(/title)
.append(/head)
.append(body)
.append(h1This is a test/h1)
.append(/body)
.append(/html)
.toString();

// make HTML to XHTML
Tidy tidy= new Tidy();
tidy.setXHTML(true);
InputStream in= new ByteArrayInputStream(page.getBytes());
org.w3c.dom.Document xhtml= tidy.parseDOM(in, null);
// translate DOM for dom4j
DOMReader xmlReader= new DOMReader();
Document document= xmlReader.read(xhtml);

Node table= document.selectSingleNode(/html/body);
System.err.println(table :  + table.asXML());
// ^ here is a
//  NullPointerException is thrown
}
}
-%


---
This SF.net email is sponsored by: eBay
Get office equipment for less on eBay!
http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5
___
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user


Re: [dom4j-user] JTidy-Dom4j-NullPointerException

2003-05-31 Thread David D. Lucas
Marco,

After looking at the code, I am not sure you realize that 
document.selectSingleNode will return null if the expression is not 
found.  This probably why it was a null pointer exception.

Try checking if (table!=null) before processing it.
Also take a look at XPE at http://www.purpletech.com/xpe and use its GUI 
along with a sample document to help you work out your XPath expressions.

Later,
Dave


--

++
| David Lucasmailto:[EMAIL PROTECTED]  |
| Lucas Software Engineering, Inc.   (740) 964-6248 Voice|
| Unix,Java,C++,CORBA,XML,EJB(614) 668-4020 Mobile   |
| Middleware,Frameworks  (888) 866-4728 Fax/Msg  |
++
| GPS Location:  40.0150 deg Lat,  -82.6378 deg Long |
| IMHC: Jesus Christ is the way, the truth, and the life.  |
| IMHC: I know where I am; I know where I'm going.  |
++
Notes: PGP Key Block=http://www.lse.com/~ddlucas/pgpblock.txt
IMHO=in my humble opinion IMHC=in my humble conviction
All trademarks above are those of their respective owners.


---
This SF.net email is sponsored by: eBay
Get office equipment for less on eBay!
http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5
___
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user


Re: [dom4j-user] JTidy-Dom4j-NullPointerException

2003-05-31 Thread David D. Lucas
Did you test with the complete file or just a snippet?
You have a default namespace defined in the root.
 .append(html xmlns=\http://www.w3.org/1999/xhtml\;)

You may want to use the /*[local-name()='html']/*[local-name()='body']
to avoid the namespace all together.
Give that a try.

Later,
Dave
--

++
| David Lucasmailto:[EMAIL PROTECTED]  |
| Lucas Software Engineering, Inc.   (740) 964-6248 Voice|
| Unix,Java,C++,CORBA,XML,EJB(614) 668-4020 Mobile   |
| Middleware,Frameworks  (888) 866-4728 Fax/Msg  |
++
| GPS Location:  40.0150 deg Lat,  -82.6378 deg Long |
| IMHC: Jesus Christ is the way, the truth, and the life.  |
| IMHC: I know where I am; I know where I'm going.  |
++
Notes: PGP Key Block=http://www.lse.com/~ddlucas/pgpblock.txt
IMHO=in my humble opinion IMHC=in my humble conviction
All trademarks above are those of their respective owners.


---
This SF.net email is sponsored by: eBay
Get office equipment for less on eBay!
http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5
___
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user