Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

Replacing Xml using java

Thread view: 
shirantha@eurocenter.lk - 16 Jan 2006 10:35 GMT
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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.