Parsing XML while ignoring comments/mixed context/PI

Hey everyone

Let's say I have three boolean variables representing whether or not to ignore comments, mixed context and PIs in an XML document

How would I go about to output the same XML file but without those three sections , depending on if they're true or false?

Are there features on parsers that you can set to ignore PI or ignore mixed context and such?

For example, if you would have this XML:

<root><?pi something><!--comment--></root>

and PI is set to false while comments is set to true, then the output should be

<root><!--comment--></root>

I tried for 2 hours to figure out how to start that or what to do but I'm really lost. Any help would be appreciated, Thanks

[776 byte] By [deanat78a] at [2007-11-26 17:56:52]
# 1
I don't think that parsers have such features. That would be a bit of overkill, really, considering you could just throw some suitable if-statements into your own code, for example to remove those things from a DOM.
DrClapa at 2007-7-9 5:10:06 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

Hi,

Yes there is method which will enable the parser to enable or disable the processing of comments,

signature is

public void setIgnoringComments(boolean ignoreComments)

Specifies that the parser produced by this code will ignore comments.

By default the value of this is set to false

i belive there are no such method to enable or disble the processing with PI.

You jst google

[url]http://java.sun.com/j2se/1.5.0/docs/api/index.html[/url]

Cheers!

Dream_Racera at 2007-7-9 5:10:06 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

yes, you can configure your parser for ignoring let's say text nodes.

however, personally, i would suggest not to do that because in the future, your code might run on some machine where the parser is not configured the same way yours was.

it is better to take care of these things in your own code but not parser.

just an experience sharing...

thanks

geomana at 2007-7-9 5:10:06 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4
Alright thanks guys, I ended up just writing my own code to ignore/not ignored these features. It was pretty fun..
deanat78a at 2007-7-9 5:10:06 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...