How to convert an xml to another Xml with a different structure...

hi
i have an xml which should be converted to a standard xml with an entirely different structure(Different elements)....can this be done with xml,xsl alone or do we need to write an java class along with them...if there are any examples..it would be of great help...plz help me out....as this is a work stopper...
given below is the kind i have
<hotelinfo>
<hotelname>RADISSON HOTEL CHENNAI </hotelname>
<address>355 C Gst Road St Thomas Mount Chennai1 600016IN</address>     <price>90.00 - 150.00</price>
<distance>2 (W)</distance>
</hotelinfo>
i need to convert it into
<propertyName>RADISSON HOTEL CHENNAI </propertyName>
<address>
<addressLine>355 C Gst Road St Thomas Mount</addressLine>
<CityName>Chennai</CityName>
<PostalCode>600 001</PostalCode>
<StateName>TamilNadu</StateName>
<CountryName>India</CountryName>
</address>
thanks in advance

Ok here is the code...
package mypack;
import java.io.File;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
* @author SM23772
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
public class Roopa {
     public static void main(String[] args) {
          File docFile = new File("Roopa.xml");
          Document doc = null;
          Document newDoc = null;
          String hname = null, task = null;
          try {
               DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
               DocumentBuilder db = dbf.newDocumentBuilder();
               doc = db.parse(docFile); //parsing Roopa.xml
               newDoc = db.newDocument(); //Created New document Object for new xml
               hname = doc.getElementsByTagName("hotelname").item(0)
                         .getFirstChild().getNodeValue();
               task = doc.getElementsByTagName("task").item(0).getFirstChild()
                         .getNodeValue();
               Node rootNode = newDoc.createElement("property-info"); //creating root node;
               Node pp = newDoc.createElement("name"); //creating a node called name
               Node taskNode = newDoc.createElement("task"); //creating a node called task
               pp.appendChild(newDoc.createTextNode(hname)); //appending a text node inisde name
               taskNode.appendChild(newDoc.createTextNode(task)); //appending the text node inside task
               rootNode.appendChild(pp); //asppending the nodes inside the root node                       
               rootNode.appendChild(taskNode);
               newDoc.appendChild(rootNode); //appending the root node to the document
               writeXmlFile(newDoc, "Dest.xml"); //function called to write the document to Dest.xml
          } catch (Exception e) {
               System.out.println(e);
     public static void writeXmlFile(Document doc, String filename) {
          try {
               // Prepare the DOM document for writing
               Source source = new DOMSource(doc);
               // Prepare the output file
               File file = new File(filename);
               Result result = new StreamResult(file);
               // Write the DOM document to the file
               Transformer xformer = TransformerFactory.newInstance()
                         .newTransformer();
               xformer.transform(source, result);
          } catch (TransformerConfigurationException e) {
          } catch (TransformerException e) {
The xml files:
roopa.xml:
<hotel>
<hotelname>RADISSON HOTEL CHENNAI</hotelname>
<more-info><task>give treate to shanu</task></more-info>
</hotel>
Dest.xml
<?xml version="1.0" encoding="UTF-8"?>
<property-info><name>RADISSON HOTEL CHENNAI</name><task>give treate to shanu</task></property-info>Please go through the code.. if u have any more concerns do let me know................
cheers
Shanu

Similar Messages

  • HOW TO CONVERT PDF FILE IN TO XML FILE?

    HOW TO CONVERT PDF FILE IN TO XML FILE

    No Office programs can open a pdf and edit the contents so you will have to get a different app to convert teh pdf into xls format. There are plenty to be found on the web.
    Rod Gill
    The one and only Project VBA Book
    Rod Gill Project Management

  • How to Convert Oracle Apps Report into XML Publisher

    Hi
    How to Convert Oracle Apps Report into XML Publisher?
    Thanks

    In Brief :
    Re: XML Publisher
    In Details :
    http://www.oracle.com/technology/products/xml-publisher/docs/XMLEBSRep.pdf

  • How to convert HL7 file into an XML

    Hi All,
    I am new to HL7,can any one tell how to convert HL7 file into an XML.Give sample demo or related links.
    My sample HL7 file is as follows how can I convert.
    FHS|^~\&||Tax ID123^Lab Name123^L|||201110191435||HL7.txt||1234567|123||
    PID|seqno|123||john^chambers^^Dr^Dr|2456 california ave^San jose^CA^85254|19601212|M
    FHS|^~\&||Tax ID123^Lab Name123^L|||File Creaqted Date|File Security|FileName||File HeaderComment||Facility|FileCreatedDateTime|File Security|File Name|File Header Comment|FileControlId|Reference File Control ID|
    PID|seqno|patientId||LastName^FirstName^MiddleName^Title^Degree|Street^City^State^zip|patientDOB|gender
    <Report>
    <FileHeader>
    <FileSendingApplication> </FileSendingApplication>
    <TaxID>Tax ID123</TaxID>
    <LabName>Lab Name123</LabName>
    <FileSendngFacilityType>L</FileSendngFacilityType>
    <FileReceivingApplication></FileReceivingApplication>
    <FileReceivingFacility></FileReceivingFacility>
    <FileCreatedDateTime>201110191435</FileCreatedDateTime>
    <FileSecurity></FileSecurity>
    <FileName>HL7.txt</FileName>
    <FileHeaderComment></FileHeaderComment>
    <FileControlId>1234567</FileControlId>
    <ReferenceFileControlID></ReferenceFileControlID>
    <FileHeader>
    <Patient>
    <seqno> </seqno>
    <patientId>Tax ID123</patientId>
    <LastName>Lab Name123</LastName>
    <FirstName>L</FirstName>
    <MiddleName></MiddleName>
    <Title> </Title>
    <Degree></Degree>
    <Street></Street>
    <City></City>
    <State>HL7.txt</State>
    <Zip></Zip>
    <patientDOB>1234567</patientDOB>
    <gender></gender>
    <Patient>
    </Report>
    Thanks
    Mani

    Hi Prabu,
    With input as in single line I'm able to get the the output but with the multiple lines of input,error was occured.Any suggestions.
    Error while translating. Translation exception. Error occured while translating content from file C:\temp\sampleHL7.txt Please make sure that the file content conforms to the schema. Make necessary changes to the file content or the schema.
    The payload details for this rejected message can be retrieved.          Show payload...
    Thanks
    Mani

  • Best way to Transform one XML to another XML using SSIS

    I am using Altova Mapforce tool to transform one XML into another XML, but now we are planning to use any other best way of using XSLT transformation. Could you guys shed me some light on different approaches and which one would be best based on time and
    cost constraint.
    In Altova Map force Tool, due to below reasons we wanted to avoid that,
    Resource cannot work parallely in single XSLT
    Maintanence is very difficult
    Licensed version of tool
    When the XML size grows, new resourse are feeling difficult to edit the XSLT etc.,
    Related to .net approaches would be best.
    Can we create XSLT by using SSIS to transfrom one xml into another xml format.
    In .net code we can do, but feel that it is time consuming due to large size of XML.
    Any other best way for handling XSLT transformation or any tool

    XSLT can be applied to an XML file fed as a source, but it does not resolve #1. I by the way do not understand this point, technically.
    For SSIS to go live in prod you need to deplete a SQL Server license (CPU + CALs).
    The time to transform in SSIS will be equal to doing in .net code as the whole SSIS is coded in .Net, too.
    Here, in this section of the forum we may not have the needed expertise in XSLT or XML transformations.
    In my IT life, XML transformations were done in Java if on a *NIX box. On Windows a C# .net app webservice did it. The most interesting implementation, and if you are a heavy users of XML is to use a dedicated database as Base X, it has an XLSLT transform
    moduleL http://docs.basex.org/wiki/XSLT_Module
    Arthur
    MyBlog
    Twitter

  • I am new to IPAD and I want o use facetime, how can I use it to communicate with my mac at home, do I need to create another account with a different email account

    I am new to IPAD and I want o use facetime, how can I use it to communicate with my mac at home, do I need to create another account with a different email account

    do I need to create another account with a different email account
    Yes, the email addresses need to be unique to each device. You may use the same Apple ID on each device, but the email address used by each device needs to be different.

  • I HAVE AN OLD 3G IPHONE , HOW DO I USE IT IN ANOTHER COUNTRY WITH A NEW SIM CARD

    I  HAVE AN OLD 3G IPHONE , HOW DO I USE IT IN ANOTHER COUNTRY WITH A NEW SIM CARD ?

    it has to be unlocked by your carrier. give them a call

  • In SQLScript, how to use EXEC to call another procedure with parameters in procedure?

    Hi experts,
    In SQLScript, How to use EXEC to call another procedure with input and output parameters in procedure?thanks very much

    Hi Sagar,
    thank you! I generate another procedure with an input parameter and an output parameter in a procedure. Then i need to call the generated procedure using EXEC. Here is my code:
    create procedure ftest1(out sum_num bigint)
    as
    begin
    declare fa_output bigint;
    declare v_sql_drop varchar(200);
    declare v_sql varchar(500);
    declare cursor c_cursor1 for select num from TABLE1;
    --v_sql_drop := 'drop procedure fe';
    --exec v_sql_drop;
    v_sql := 'create procedure fe(in i_num bigint,out o_num bigint) as begin';
    v_sql := :v_sql || ' o_num := :i_num * 2 + :i_num * :i_num;';
    v_sql := :v_sql || ' end';
    exec v_sql;
    open c_cursor1;
    for c_item as c_cursor1 do
    exec 'call fe(c_item.num,o_num=>fa_output)';
    if sum_num is null then
    sum_num := fa_output;
    else
    sum_num := :sum_num + fa_output;
    end if;
    end for;
    close c_cursor1;
    end;
    The underline code is using exec to call the generated procedure. But this method cannot work. Any suggestion? thanks again!

  • Could someone please tell me how to convert a powerpoint to a movie, with a voice over? thankyou :)

    could someone please tell me how to convert a powerpoint to a movie, with a voice over? thankyou

    Open the powerpoint presentation, on the click on the 'file' button located at the top left of the menu bar, click on 'save as' at the bottom of the window that opens you should see a dropdown format gliff that says powerpoin presentation .pptx; click on the gliff and choose 'movie.mov'

  • Is there a way to transfer or copy all my apps to another iPad with a different account? I was required in my job to use the one at work, but I would like to also see my current set ups and apps as in my personal one. Thank you so much!

    Is there a way to transfer or copy all my apps to another iPad with a different account? I was required in my job to use the one at work, but I would like to also see my current set ups and apps as in my personal one. Thank you so much!

    What I suggest is that you try to pair your apple ID with you company ipad and see if it works.
    Here is why::
    I believe that the Apple rules let you. They are something like:
    -- for a shared iDevice, you may put the app on one device
    -- for a device you use exclisively, you may put the app on five (or some number) of iDevices
    I'm not lawyer, so how you interpred this is a question.
    Now, you need to figure out how to do this.
    In the past at least, apple used this terminalogy.
        Personal
        Institution
        Layered. combines personal & institution.
    It depends on how your company has configured the iPad.
    I have read where you can have upto three apple id per device.

  • Link to another portlet  with a different layout

    Hello
    Can somebody point me how to create a link in one portlet which opens
    another portlet with a different layout.
    I have portlet one in a 3 column layout, I want to open portlet 2 in a
    single column layout.
    TIA
    Gowtham.

    Do you sync to the same computer which has both your and her purchases on ? If you do then she should be able to sync them to her phone from it.
    If you use different computers then you could copy them from your computer to her computer (if they are not on your computer then you could re-download them on it). You can find where they are stored on your computer by right-clicking (control-click on a Mac) one of them in the Apps part of your iTunes library and selecting 'show in explorer' ('finder' on a Mac). You can then copy them to, for example, a flashdrive and then add them (you will need to authorise your account via the Store > Authorise This Computer menu option) to her computer's iTunes via File > Add To Library and she can then sync them.
    If you log into your account on her phone or her computer and re-download those apps on it then you risk tying the phone or computer to your account for 90 days : http://support.apple.com/kb/HT4627

  • How can my wife and I share cloud with 2 different login's

    How can my wife and I share cloud with 2 different login's

    If you each have separate iCloud accounts with different IDs, you can add the other person's account to your device(s) by going to Settings>Mail,Contacts,Calendars>Add Account>iCloud and signing in with their ID.  These "secondary accounts" will sync mail, contacts, calendars, reminders and notes.

  • How can you use iMessage between 3 iPads with 3 different users but only one Apple ID?

    how can you use iMessage between 3 iPads with 3 different users but only one Apple ID?

    No you do not need separate Apple ID's in order to use 3 devices with one Apple ID. I use 4 devices to Message and FaceTime and all use the same Apple ID. You do need to add additional email addresses for the other devices.
    Look at this very informative video for the instructions.
    http://macmost.com/setting-up-multiple-ios-devices-for-messages-and-facetime.htm l

  • I've set up email on my iPad (talk mails when connected to my home router and ISP. When connected to a router at another location with a different ISP I can receive mail but not send it. Is there any way round this

    I've set up email on my iPad (talktalk.net) and can send and receive mails when connected to my home router and ISP. When connected to a router at another location with a different ISP I can receive mail but not send it. Is there any way round this?

    I've set up email on my iPad (talktalk.net) and can send and receive mails when connected to my home router and ISP. When connected to a router at another location with a different ISP I can receive mail but not send it. Is there any way round this?

  • How can i split a long single video with many different scenes in it ?

    how can i split a long single video with many different scenes in it ? in premiere pro cs3

    Yep better ask in the Premeire Pro forums, but while loading their forum page check the cutter tool (C) it will allow you to cut your footage

  • How do i update applications that were downloaded with a different apple id

    how do i update applications that were downloaded with a different apple id

    You can't. The iLife apps get tied in with not only the Apple ID, but the Mac that they were accepted on.The Mac App Store will always remeber that the iLife apps have been accepted once before already on this Mac and will only offer to update them with the Apple ID into whose account they were accepted.

Maybe you are looking for

  • Photos on photo stream not in library after import from memory card

    I imported photos from a memory card and they appear on the photo stream but not in the event I created in the library at the time of import. How do I get the photos into the event in the libray. Clicking and dragging doestnt work.

  • Having trouble with Mail

    Are there any other ports other than 995?

  • Menu becomes inactive.

    When i try to add or import anything, no window opens and all selections in the menus become inactive (grey)

  • Order operation change

    Hi, I must modify order operation. Have you a sample program with function 'IBAPI_ORDER_OPERATION_CHANGE'? Thanx in advance. CV

  • No nutrient listing maintained for the nutrient group

    Hi Team I have maintained the nutrients in the nutrient group. I have given the area, UOM. I can find the nutrient group in the drop down while chaning the recipe. But once i select the nutrient gorup i get the warning message "No nutrient listing ma