Converting Document object into XML file

I was wondering how to convert a document object to XML file? I have read the documentation about document and Node but nothing explains the procedure of the conversion. Ive been told that it can be done, but not sure how. I have converted an XML file into Document by parsing DocumentBuilder. Just not sure how to do the reverse. Any help appreciated.

TransformerFactory tf = TransformerFactory.newInstance();
Transformer trans = tf.newTransformer();
trans.transform(new DOMSource(yourDOMsRootNode), new StreamResult(new FileOutputStream(yourFileName)));or something a lot like that.

Similar Messages

  • Converting Dom Document object into XML file removes the DTD

    Hi All
    My xml is dtd. I have one xml file. i changed the node value after that i want to create a xml file with the same name. I created new xml file but i am not seeing the old dtd in the new file. This process is done with the help of jaxp.
    My code is given below
    File fileInput = new File("input.xml");
              File fileOutput = new File("output.xml");
              DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
              factory.setExpandEntityReferences(false);
              DocumentBuilder builder = factory.newDocumentBuilder();
              Document document = builder.parse(fileInput);
              TransformerFactory tFactory = TransformerFactory.newInstance();
              Transformer transformer = tFactory.newTransformer();
    transformer.setOutputProperty(javax.xml.transform.OutputKeys.INDENT, "true");
              transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
              DOMSource source = new DOMSource(document);
              FileOutputStream fos = new FileOutputStream(fileOutput);
              StreamResult result = new StreamResult(fos);
              transformer.transform(source, result);
    Thanks in advance

    The Transformer API does not guarantee the preservation of that information. You may want to check the DOM L3 Load/Save package (http://java.sun.com/javase/6/docs/api/index.html). Alternatively, you may force things by setting the additional output properties 'doctype-public' and 'doctype-system'.

  • How to convert database table into xml file

    Hi.
    How to convert database table into XML file in Oracle HTML DB.
    Please let me know.
    Thanks.

    This not really a specific APEX question... but I search the database forum and found this thread which I think will help
    Exporting Oracle table to XML
    If it does not I suggest looking at the database forum or have a look at this document on using the XML toolkit
    http://download-east.oracle.com/docs/html/B12146_01/c_xml.htm
    Hope this helps
    Chris

  • How to convert Java Objects into xml?

    Hello Java Gurus
    how to convert Java Objects into xml? i heard xstream can be use for that but i am looking something which is good in performance.
    really need your help guys.
    thanks in advance.

    There are apparently a variety of Java/XML bindings. Try Google.
    And don't be so demanding.

  • Converting EJB Object into XML

    All:
    Suppose I have an EJB that is named MyDog, it has attributes as follows:
    name
    breed
    weight
    age
    Is there a way to convert this Object into an XML document? Something like:
    <?xml version=\"1.0\" ?>
    <MyDog>
    <name>Bubba</name>
    <breed>Australian Shepherd</breed>
    <weight>65 lbs</weight>
    <age>6 years old</age>
    </MyDog>
    I can't find any information on doing this - any ideas, links, etc? There has to be a way to do this, but I can't find it. I'm welcome to any ideas out there!

    check JAXB - might be usefull for you: http://java.sun.com/xml/jaxb/index.html

  • Saving business objects into xml file

    I have the following XML file parsed into a DOM tree, with 2 different types of nodes "TestCase" and
    "RealCase". Then I mapped each type to a different type of business object, TestCaseObj and RealCaseObj.
    Now, there may be addition of new objects, or modifications to the data stored in the business objects
    by my application. Eventually when I save the business objects back into the XML file, how should I go
    about doing that?
    <ROOT>
    <TestCase TestID="T1">
         <Element1>Data1</Element1>
         <Element2>Data2</Element2>
    </TestCase>
    <TestCase TestID="T2">
         <Element1>Data1</Element1>
         <Element2>Data2</Element2>
    </TestCase>
    <RealCase ID="R1">
         <Element1>Data1</Element1>
         <Element2>Data2</Element2>
         <Element3>Data3</Element3>
    </RealCase>
    <RealCase ID="R2">
         <Element1>Data1</Element1>
         <Element2>Data2</Element2>
         <Element3>Data3</Element3>
    </RealCase>
    </ROOT>

    The DocumentBuilder class does not allow you to parse a portion of the xmlfile. Therefore, it will not be possible to read "TestCase" into the DOM without bringing in "RealCase" nodes as well. As such, these codes will parse the entire xml file into DOM:
    DocumentBuilder builder = builderFactory.newDocumentBuilder();
    Document document = builder.parse( xmlFile );
    However, your problem can be solved by reading only "TestCase" nodes in DOM, as follows:
    NodeList elementNodeList =
    elementNode.getElementsByTagName("TestCase");
    Your codes will then change the data in the elementNodeList, without affecting "RealCase" although it is loaded into DOM. You can be sure that elementNodeList contains only "TestCase" nodes.
    Once you have made your changes, save the DOM back to the XML file, using the serializer method as discussed earlier.
    Good luck.

  • How to convert a string into xml file

    Hi,
    i have a string . the string contain fully formated xml data. i mean my string like below
    <?xml version="1.0"?>
    <PARTS>
       <TITLE>Computer Parts</TITLE>
       <PART>
          <ITEM>Motherboard</ITEM>
          <MANUFACTURER>ASUS</MANUFACTURER>
          <MODEL>P3B-F</MODEL>
          <COST> 123.00</COST>
       </PART>
       <PART>
    ......................i want to convert it into an xml file
    can u help me?
    thank u

    Thank you Paul Clapham,
    and sorry ..
    i have some other doubt.. regarding xml
    i want to post an XML file from one server(Server_1) to other server.(Server_2)
    To generate an xml file i used DOM in Server_1.
    using xml.transform , StringWriter i converted it into String.
    I post the string to another server and there i will parse it.
    for that i write the code like below in servlet in server_1
    <form name=fn action=http://localhost:8080/server_2/parseXMl.do method=post>
    <input type=hidden name=xmlFile value="+Xmlstring+">
    <input type=submit >is this process is correct?
    Some of the turorial told that use web-services/XML-RPC
    but i new to both..
    I want to complete it using my knowledge only/
    Is it possible to do it?
    Or any other alternative?
    can help me?

  • Converting webi reports into Xml

    Hi all ,
    Can we convert the BO Edge 3.1 Webi reports into XML Format?
    Pls suggest me a solution and if we can convert, pls describe the procedure to be followed inorder to convert the reports into xml files?
    Thanks in advance,
    Thanks & regards,
    Amrita.B

    Hello,
    While this is not possible (directly) for the entire report, you could do one of the following:
    1. If you're on SP2 (or higher), you could publish Webi Report Content as a web service. There is more information in the pdf at http://help.sap.com/businessobject/product_guides/boexir31SP2/en/xi31_sp2_webi_rich_en.pdf (pg 304) .
    2.  Use QAAWS to publish queries used in the report as web services.
    Best,
    Srinivas

  • Serializing Java Objects to XML files

    Hi,
    We looking for SAP library which can serialize Java Objects into XML files.
    Can you point us were to find it ?
    We have found such open source library called "XStream" at the following link
    http://www.xml.com/pub/a/2004/08/18/xstream.html
    Is it allowed to use that library inside SAP released software ?
    Thanks
    Orit

    How about https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/webcontent/uuid/83f6d2fb-0c01-0010-a2ba-a2ec94ba08f4 [original link is broken] [original link is broken]? Depends on your use cases...
    Both are supported in SAP NW CE 7.1.
    HTH!
    -- Vladimir

  • Regarding conert the object to XML file

    Hi all
    i want to convert the object to XML file in my application.plz give me the sample code
    Thanks in advance

    Or you could make your object JavaBean compliant and save it using XMLEncoder and reload it by using XMLDecoder.
    To be JavaBean compliant you basically need a no arg constructor and getters and setters for all fields you want to keep.
    Aye,
    Jim

  • Conversion of DOM object to XML file

    Hi
    Is there a direct method for conversion of a Document object to xml file? My code is like this
    Transformer aTransformer = tranFactory.newTransformer();
              System.out.println("Tansformers :"+aTransformer);
              aTransformer.setOutputProperty(OutputKeys.INDENT, "yes");
              DOMSource src = new DOMSource(resultDocument);
              System.out.println("src :"+src);
              Result dest = new StreamResult(new FileOutputStream(new File(filepath)));
              System.out.println("desc :"+dest);
              aTransformer.transform(src, dest);
    but the line DOMSource src = new DOMSource(resultDocument);
    is giving me an error like "undefined constrctor" . what must be the problem?
    Thanks

    DOMSource src = new DOMSource(resultDocument);
    resultDocument should be of type org.w3c.Node

  • How can convert HTML file into xml file?

    Hi,
    I am receving one HTML file as an input and i want to convert that receiving(html file) into .xml file.Is there any converter (tools)to do this.Pls if any give me the details with regard.
    Regards,
    mahesh.

    Use the HTMLEditorKit to parse the html file.
    this kit is having the callback methods which
    are called wenever the tag appears in the HTML
    stream.

  • How should convert text file into XML file?

    I do a project "WEB SERVER LOG ANALYZER" using JSP. For that i copy the content of log file into the other file . how i convert it into XML file . xplain with coding

    Read this [page.|http://www.devx.com/getHelpOn/10MinuteSolution/20356]

  • How to convert Xls file into Xml file

    Hi,
    I am trying to convert Xls file into Xml  but there  is no any direct procedure for it
    Pls help me out to convert Xls file into Xml file
    Thanks
    Anushree

    you will require to write a module in your file adapter for the same.
    ref: /people/sap.user72/blog/2005/07/04/read-excel-instead-of-xml-through-fileadapter as mentioned in the earlier post.
    Else you can also use Conversion Agent to read the same.
    Ref: http://help.sap.com/saphelp_nw04/helpdata/en/43/4c38c4cf105f85e10000000a1553f6/content.htm

  • How to convert text file into xml file format with and check that with DTD

    I have an text file with | seperator . I have to convert this to an xml file and check with DTD present with me..
    plz help me out

    can i get some code that how to compare the xml with dtd or just give the DTD name with an XML

Maybe you are looking for

  • How do i get my itunes music on my iPhone 5

    Not sure how I sync my music on my iphone from my macpro or the cloud

  • SOAP adapter or file adapter

    Hi Gurus, Non-SAP system B ->PI->Non-SAP system A. The request is sent from non-SAP application  A to Pi and this is routed to another non SAP system sap example SYSTEM B. Then B sends the response in the form of XML file to Application A via PI. Thi

  • SQL Server Analysis Services (PowerPivot) instance returned the following error:

    SQL Server Analysis Services (PowerPivot) instance returned the following error: Error Code: 3241607174 Description: A connection corresponding to the embedded PowerPivot data was not found in the Excel workbook, file 'C:\Program Files\Microsoft SQL

  • Where would I post to ask about finding new mac software?

    I would like to ask if anyone knows of software for Mac's that allows one to build a database of their temporary staff, but I a m not sure where I would post this question. Any help would be appreciated. Thanks.

  • N73 and yahoo!go

    N73 features everywhere its bundled with y!go, is it true? In fact i buy önly for ygo, but my phone has no y!go, i ask nokia customer care, they told n73 is nt supported for y!go. Any kind hearted person Please tell where to get yahoo!go for my N73.