File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes how to Read and write XML file with some conditions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "how to Read and write XML file with some conditions" Watch "how to Read and write XML file with some conditions" New topic

how to Read and write XML file with some conditions

Ranch Hand

Joined: Mar 10, 2005
Posts: 31

My Java program has to read an XML file under Root tag, the root tag is having Many Child Tag, the code has to show the name of the Child tag and it has to read some particular tags under Child tag and it has to write that tag contents in a file(.txt or .xml).

And the code also have to Skip some child tags and skipped child tags (particular tags in skipped child tags have to be read and write in another file) will start with a different Name(Only two tags will be added extra, compared to other child tags) but the contents and the tags it has to read and write will be the same as the child tag as in first case, but this has to have the contents of the newly added tags also.

But how to Achieve this. Please help me in coding.

Please guide me.

Thanks In Advance,
[ September 14, 2006: Message edited by: P.Sivaraj ]
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

We have a forum specifically for XML questions. I'll move this there.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12678
You need to proceed step by step - first get the code for reading an XML document into memory as a DOM (Document Object Model).
Sun's XML tutorial may be a big help to get started.
After you have a DOM, you can apply various methods to locate specific elements, but first things first.


Java Resources at
I agree. Here's the link:
subject: how to Read and write XML file with some conditions
Similar Threads
Search for a directory by its name only
Problem in Reading XML file through Java
Importing multiple external XSD files
how to generate a xml file on submit action with all the form data
LDIF contents display in Tree