Replacing Xml using java

S

shirantha

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.
 
E

Erik Andreas Brandstadmoen

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

<...>
<client>
<name>Charles Darwin页页页</name>
<address>32, Vincent Av, London</address>
<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
 
S

shirantha

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,817
Latest member
AdalbertoT

Latest Threads

Top