Solved

Use JAVA to convert tab delimited text file to xml

Posted on 2006-06-21
4
673 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jboss 7.1 start up error 1 64
ejb entity bean example 2 39
ejb mdb examples 1 21
Why doesn't this text field show up on my Applet frame? 2 28
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

730 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