[jdom-interest] Getting comments in a Document

Jason Hunter jhunter at xquery.com
Wed May 10 15:07:47 PDT 2006


getContent() only works one level deep.  getDescendants() might work 
better for you (it returns a lazy Iterator), or an XPath like //comment().

-jh-

David Patterson wrote:
> This may be the wrong forum, but I hope someone knows this answer. I’m 
> using Java 1.4 with the default parser and JDOM. I process an XML 
> document that has comments in it. After getting a good Document object, 
> my code has:
> 
>  
> 
>             Filter comments = new ContentFilter( ContentFilter.COMMENT );
> 
>             List commentList = newPrelDoc.getContent( comments );
> 
>             System.out.println( "commentList size is: " + 
> commentList.size());
> 
>  
> 
> And, I’m getting a value of zero as the size. (A) Is this the right way 
> to use this filter? (B) Is it known that the default parser blocks 
> comments? (C) Is there a magic incantation to get it to pass comments 
> along? (D) Does a different parser pass comments through?
> 
>  
> 
> Thanks.
> 
>  
> 
>  
> 
> David R. Patterson
> 
>  
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> To control your jdom-interest membership:
> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com


More information about the jdom-interest mailing list