Hi, Fellas
I have a problem regarding an Xml document, where I need to remove
blocks of xml code, if
there are control characters found in a block. (you know those squares
that sometimes appear). Of course i need to manipulate the code using
Java API's
What i want to do is when i find a control character (which could come
anywhere inside a
client node), I want to remove the entire client block from the
document and return it as a
string in a java class. In the example code below Two <client> blocks
contain control characters, so those blocks has to be removed.
I really cant think of an efficient way to do this. an Xml document may
contain several hundreds of such client node blocks.
Please, if any of u guys can think of mechanism it would be of great
help
Example Xml code
<...>
<client>
<name>Charles Darwin</name>
<address>32, Vincent Av, London</address>
<info>Bill Lawry</info>
</client>
<client>
<name>Richie Benaud</name>
<address>32, Vincent Av, London</address>
<info>Some information goes here</info>
</client>
<client>
<name>Bill Lawry</name>
<address>32, Vincent Av, London</address>
<info>Some information goes here</info>
</client>
<client>
<name>Mark Waugh</name>
<address>32, Vincent Av, London</address>
<info>Some information goes here</info>
</client>
<...>
Appreciate your time
Thanks
Shiran.
Erik Andreas Brandstadmoen - 16 Jan 2006 12:08 GMT
Hi, Shiran.
This shouldn't be too bad to do in Java. I would use a SAX parser
directly, not a DOM document, if efficiency is a big concern.
> Example Xml code
>
[quoted text clipped - 4 lines]
> <info>Bill Lawry</info>
> </client>
I don't have time to put this out in big letters, but, in brief:
* Register a SAX handler for the <name> tag, where you look for
occurences of multi-byte characters (or some other criteria for which
characters you want to remove)
* Use SAX to run through the document and call the handler on every
occurence of the <name> tag
Good luck!
Regards, Erik Brandstadmoen
shirantha@eurocenter.lk - 19 Jan 2006 04:20 GMT
I wonder if you could give me a small method (for the above example)
using SAX
to do this. I am pretty new to java xml, i am finding it confusing how
to do it.
The method should return <client><name>Charles
Darwin</name><address>32, Vincent Av,
London</address><info>BillLawry</info></client>
something like this as a string.
Thanks
Shiran.