This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes Problem in Reading XML file through Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Problem in Reading XML file through Java" Watch "Problem in Reading XML file through Java" New topic
Author

Problem in Reading XML file through Java

P.Sivaraj
Ranch Hand

Joined: Mar 10, 2005
Posts: 31
Hi All,

I am having problem in reading XML through XML.The code has to read the XML file and after reading it has to have the output in Another .txt or .Xml. My Program is working fine for Similar tags, for eg:

<name="abc">
<xyz>abcd</xyz>
<sjsjd>kjh</sjsjd>
<jhd>
<jdshf>Some number</jdshf>
</jhd>
</name>
My Program Is taking the values inside tags "xyz","sjsjd","jdshf". It is working fine if the file is having only the same format, but My File is having another formats of XML too with some extra Tags for eg:

<if something = "xyz == 2" type "something">
<then>
<name="abc">
<xyz>abcd</xyz>
<type>kjh</type>
<jhd>
<jdshf>Some number</jdshf>
</jhd>
</name>
</then>
</if>

I have to make the code fulfill this condition also, if it finds this <if> tag means it has to copy the contents inside that tag in a different file. So The program has to skip this tags in the first file & has to copy in the next file.

My program has to create two files,Please help me how to achive this through Java Coding. I am facing the problem of reading the Tag Contents under <if> also in the same file because of its same tag names, plesae tell me how to do in coding.

Thanks in Advance,
Siva.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

So, you read in one XML file, and you want to do something with the data in it and output a new XML file or a plain text file.

You're using some kind of parser that you wrote yourself that understands the <if> tag etc.

What you want to do is exactly what XSLT was invented for. Have a look at an XSLT tutorial.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Moving to our XML forum...


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in Reading XML file through Java
 
Similar Threads
unable to use more than 2 <bean:message. tags in jsp
Servlet to read XML tags from Client
JSTL: Help needed in retrieving data from xml, setting it and printing
how to Read and write XML file with some conditions
Castor Marshalling Problem