Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Converting XML to Non xml and vice versa

 
Aryan Khan
Ranch Hand
Posts: 290
Java Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Aryan Khan
Ranch Hand
Posts: 290
Java Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 290
Java Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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] </>
</>
--------------------------
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic