You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Anthony Saucet <an...@freesbee.fr> on 2003/05/22 14:38:06 UTC

don't want the parser to retrieve comments or text nodes in the XML file

I'm using the xerces2.0.0 DOMParser to parse XML files.
I'm building a DOM tree, but I want the parser not to retrieve comments 
or text nodes.
Here's my code:
	DOMParser parser = new DOMParser();
	try {
	  parser.parse(xmlFile);
	  document = parser.getDocument();
	}
What I'm trying to do is: when the parsing is finished, I scan the tree 
and do node.removeChild(child) when child is a Text or Comment node. But 
it still remains some.

Is there a way to do that properly during the parsing? a feature to set?

many thx
anthony


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: don't want the parser to retrieve comments or text nodes in the XML file

Posted by Arno Schatz <li...@arnoschatz.de>.
Yes, the DOM Level 3 LS API is implemented in Xerces, I am using it. Have a look at 
org.w3c.dom.ls.DOMBuilderFilter. It has the API for accepting Nodes while parsing. 
register it with any parser which implements rg.w3c.dom.ls.DOMBuilder, (in Xerces the 
parser you may use is org.apache.xerces.parsers.DOMBuilderImpl).

-Arno

Joseph Kesselman wrote:
> 
> 
> 
>>What I'm trying to do is: when the parsing is finished, I scan the tree
>>and do node.removeChild(child) when child is a Text or Comment node. [...]
>>Is there a way to do that properly during the parsing? a feature to set?
> 
> 
> The proposed DOM Level 3 load/save API included a filtering mechanism, last
> time I looked at it. I don't know whether that's been implemented.
> 
> If not, the simplest answer is to set up a SAX filter which has this
> effect, run a SAX parser into that, and run the filter's output into a
> SAX-to-DOM builder. (Or apply that same concept at the XNI level; less
> portable but more efficient, and you might be able to reuse some of the the
> existing XNI components.)
> 
> ______________________________________
> Joe Kesselman, IBM Next-Generation Web Technologies: XML, XSL and more.
> "The world changed profoundly and unpredictably the day Tim Berners Lee
> got bitten by a radioactive spider." -- Rafe Culpin, in r.m.filk
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: don't want the parser to retrieve comments or text nodes in the XMLfile

Posted by Elena Litani <el...@ca.ibm.com>.
Joseph Kesselman wrote: 
> >What I'm trying to do is: when the parsing is finished, I scan the tree
> >and do node.removeChild(child) when child is a Text or Comment node. [...]
> > Is there a way to do that properly during the parsing? a feature to set?
> 
> The proposed DOM Level 3 load/save API included a filtering mechanism, last
> time I looked at it. I don't know whether that's been implemented.


Yes, the DOM L3 filtering is implemented in Xerces. See the following:
http://www.w3.org/TR/2003/WD-DOM-Level-3-LS-20030226/load-save.html#LS-DOMBuilder
http://xml.apache.org/xerces2-j/dom3.html
http://xml.apache.org/xerces2-j/faq-dom.html#faq-3

Thank you,
-- 
Elena Litani / IBM Toronto

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: don't want the parser to retrieve comments or text nodes in the XML file

Posted by Joseph Kesselman <ke...@us.ibm.com>.



>What I'm trying to do is: when the parsing is finished, I scan the tree
>and do node.removeChild(child) when child is a Text or Comment node. [...]
> Is there a way to do that properly during the parsing? a feature to set?

The proposed DOM Level 3 load/save API included a filtering mechanism, last
time I looked at it. I don't know whether that's been implemented.

If not, the simplest answer is to set up a SAX filter which has this
effect, run a SAX parser into that, and run the filter's output into a
SAX-to-DOM builder. (Or apply that same concept at the XNI level; less
portable but more efficient, and you might be able to reuse some of the the
existing XNI components.)

______________________________________
Joe Kesselman, IBM Next-Generation Web Technologies: XML, XSL and more.
"The world changed profoundly and unpredictably the day Tim Berners Lee
got bitten by a radioactive spider." -- Rafe Culpin, in r.m.filk


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org