aspose file tools*
The moose likes XML and Related Technologies and the fly likes Converting XML to Non xml and vice versa Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Converting XML to Non xml and vice versa" Watch "Converting XML to Non xml and vice versa" New topic
Author

Converting XML to Non xml and vice versa

Aryan Khan
Ranch Hand

Joined: Sep 12, 2004
Posts: 290

Just wanted to share this.
I was looking for an easy solution for converting delimited, fixed length to xml and vice versa

Came across xsugar (google xsugar). Very nice, easy but yet powerful.

Ahmad


OCP/MCP/SCJP/SCWCD/IBM XML/SCMAD/SCEA-1
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12675
    
    5
That looks really interesting - thanks for bringing it to the forum. When you get more experience with XSugar, please give us a progress report.

Bill


Java Resources at www.wbrogden.com
Aryan Khan
Ranch Hand

Joined: Sep 12, 2004
Posts: 290

Yeah just an example of using xSugarXsugar:

Convert a fixed length file to xml:

1.Fixed length file contents:
(students.txt)
---------------------------------------------
John Doe ((john_doe@notmail.org) 19701234 Ahmad Khan
Jane Dow ((dow@bmail.org) 19785678 Ahmad Khan
John Doe ((john_doe@notmail.org) 19701234 Ahmad Khan
Jane Dow ((dow@bmail.org) 19785678 Ahmad Khan
---------------------------------------------

2.Xsugar uses .xsg file to store the transformation information:
(students.xsg)
---------------------------
Name1 = [a-zA-Z]+(\ [a-zA-Z]+)*{3}
Name = [a-zA-Z\ ]{10}
FName = [a-zA-Z\ ]{10}
Email = [a-zA-Z._]+\@[a-zA-Z._]+
Id = [0-9]{8}
NL = \r\n|\r|\n

file : [persons p] = <students> [persons p] </>

persons : [person p] [NL] [persons more] = [person p] [persons more]
: =

person : [Name name] "((" [Email email] ")" __ [Id id] __ [FName fname] =
<student sid=[Id id]>
<name>[Name name] </>
<email>[Email email] </>
<fname>[FName fname] </>
</>
----------------------------------------------------

Now just run:

java -jar xsugar-all.jar students.xsg students.txt

It has got an api which you can use in your hava application.

Look for dk.brics.xsugar.Main.

Hope this helps.

Ahmad
Aryan Khan
Ranch Hand

Joined: Sep 12, 2004
Posts: 290

Sorry the correct .xsg file is :
--------------------------
Name = [a-zA-Z\ ]{10}
FName = [a-zA-Z\ ]{10}
Email = [a-zA-Z._]+\@[a-zA-Z._]+
Id = [0-9]{8}
NL = \r\n|\r|\n

file : [persons p] = <students> [persons p] </>

persons : [person p] [NL] [persons more] = [person p] [persons more]
: =

person : [Name name] "((" [Email email] ")" __ [Id id] __ [FName fname] =
<student sid=[Id id]>
<name>[Name name] </>
<email>[Email email] </>
<fname>[FName fname] </>
</>
--------------------------
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Converting XML to Non xml and vice versa
 
Similar Threads
When does <h:datatable> support sets?
Methods: parameters
String to DATE
object to XML
UML plugin for Eclips 3