Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to convert a text file into an xml?

 
samir vasani
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Please guide for convertion of .txt to .xml
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it plain text or does it have some internal formatting?

What should the format of the XML be, and what is its purpose? This is important because there's an unlimited number of ways to convert an arbitrary text file into an XML file.
 
samir vasani
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lester Burnham wrote:Is it plain text or does it have some internal formatting?

What should the format of the XML be, and what is its purpose? This is important because there's an unlimited number of ways to convert an arbitrary text file into an XML file.



The formate of my .txt is:

invoice_number product_number product_description
12321212 45612 abcdasksalaknsdlandaks
67812121 78921 xyzasdjcakbjasbckasccbc
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK. Various classes in the java.io package and the use of some methods in the String class should be sufficient to handle that.
 
samir vasani
Ranch Hand
Posts: 65
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lester Burnham wrote:OK. Various classes in the java.io package and the use of some methods in the String class should be sufficient to handle that.


I am having the text file in the following formate.

Java|http://www.rgagnon/javahowto.htm
PowerBuilder|http://www.rgagnon/pbhowto.htm
Javascript|http://www.rgagnon/jshowto.htm
VBScript|http://www.rgagnon/vbshowto.htm

And the code for the above file is



This works perfect for the above given .txt file

But the on which i wish to work is in the following formate:
I have attached the file,becuase the view of the .txt is imperfect.
So please find the attached copy and go through it

So i to change the code for the above formate
Help me please to resolve it

[ UD: In the future, please UseCodeTags when posting code of an length. It's unnecessarily hard to read the code ptherwise, making it less likely that people will bother to do so. ]
 
Varun Chopra
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to look at JAXB or Castor for this.
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have attached the file,becuase the view of the .txt is imperfect.

I don't see that; try posting it.

You need to look at JAXB or Castor for this.

No. There are any number of ways of creating XML, including the one shown in samir's code. What's more, tools like JAXB and Castor suppose the existence of Java classes that are mapped to XML elements - yet samir's posts don't sound like those classes exist.
 
samir vasani
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lester Burnham wrote:
I have attached the file,becuase the view of the .txt is imperfect.

I don't see that; try posting it.

You need to look at JAXB or Castor for this.

No. There are any number of ways of creating XML, including the one shown in samir's code. What's more, tools like JAXB and Castor suppose the existence of Java classes that are mapped to XML elements - yet samir's posts don't sound like those classes exist.



I want guidence or code for the following text formate

invoice_number product_number product_description
B4763020 64012 GAMIMUNE N 5% 10ML
12345555 32323 abcdswbfjwbcbwjcb
12345123 12323 abaswbfjwbcbwjcb
54545555 32223 zxcdswbfjwbcbwjcb
14545555 44323 abcdswbfjwbcbwjcb


please notuce one thing that there is a tab space("/t") between each column
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This:

doesn't look substantially different from this:

Different delimiter character, and different number of items per line, but that's about it. What problems are you encountering while adapting your earlier code?
 
samir vasani
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lester Burnham wrote:This:

I want out put of xml in the following formate

Different delimiter character, and different number of items per line, but that's about it. What problems are you encountering while adapting your earlier code?
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you have so far? What does it do, and where are you stuck making it do what you want it to do?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic