Solved

Use JAVA to convert tab delimited text file to xml

Posted on 2006-06-21
4
682 Views
Last Modified: 2012-06-27
hi to any experts out there...

I have a tab-delimited text file "contents.txt" with the following contents :-

contents.txt
--------------
FE Global Electronics Pte Ltd          kh.loh@fe-electronics.com     12345678     12345678     Buyer          595171083    
Electronic Components     Manufacturer    


How to convert the text file to a xml file using java programming?

desired output of the xml file: -

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE Pip3A4PurchaseOrderRequest SYSTEM "3A4_MS_V02_03_PurchaseOrderRequest.dtd"><Pip3A4PurchaseOrderRequest>
   <fromRole>
      <PartnerRoleDescription>
         <ContactInformation>
            <contactName>
               <FreeFormText>FE Global Electronics Pte Ltd</FreeFormText>
            </contactName>
            <EmailAddress>kh.loh@fe-electronics.com</EmailAddress>
            <facsimileNumber>
               <CommunicationsNumber/>
            </facsimileNumber>
            <telephoneNumber>
               <CommunicationsNumber/>
            </telephoneNumber>
         </ContactInformation>
         <GlobalPartnerRoleClassificationCode>Buyer</GlobalPartnerRoleClassificationCode>
         <PartnerDescription>
            <BusinessDescription>
               <GlobalBusinessIdentifier>595171083</GlobalBusinessIdentifier>
               <GlobalSupplyChainCode>Electronic Components</GlobalSupplyChainCode>
            </BusinessDescription>
            <GlobalPartnerClassificationCode>Manufacturer</GlobalPartnerClassificationCode>
         </PartnerDescription>
      </PartnerRoleDescription>
   </fromRole>
</Pip3A4PurchaseOrderRequest>
0
Comment
Question by:feliciayong
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 30

Expert Comment

by:Mayank S
ID: 16956894
You can use this for creating XML files:

http://www.javaalmanac.com/egs/org.w3c.dom/pkg.html

0
 
LVL 24

Expert Comment

by:slyong
ID: 16956898
0
 
LVL 10

Accepted Solution

by:
mukundha_expert earned 500 total points
ID: 16957034


            String in = "FE Global Electronics Pte Ltd\tkh.loh@fe-electronics.com\t12345678\t12345678\tBuyer\t595171083\tElectronic Components\tManufacturer";
            
            String[] str = in.split( "\t" ) ;
            
            for ( int i = 0 ; i < str.length ; i ++ )
                  System.out.println( str[i] ) ;
            
            DocumentBuilderFactory fact = DocumentBuilderFactory .newInstance() ;
            DocumentBuilder builder = fact.newDocumentBuilder() ;
            org.w3c.dom.Document doc = builder.newDocument() ;
            
            Element root = doc.createElement( "Pip3A4PurchaseOrderRequest" ) ;
            doc.appendChild( root ) ;

Similarly add all the nodes to the root
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16957581
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question