Formatting XML written to a file

Hi,
I am trying to write runtime data (XML) to a file. I am doign the following to write to the file:
public void saveFile() throws Exception {
try {
TransformerFactory transformerFactory =
TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(doc);
OutputStream output = new FileOutputStream(XMLFile);
StreamResult result = new StreamResult();
transformer.transform(source, result);
output.flush();
output.close();
} catch (Exception x) {
throw x;
The output from the above code is a clutter of elements. All the elements are on the same line some times.
1) How can I format the output? (Indent the elements in the file)
Is there a way to achieve this?
Sometimes, I see a square character at the end of some lines. I thought the output file is corrupt because of this character. But it does not seem to be a problem.
2) How do I avoid this character?

Duplicate of the following thread:
Format XML data when writing to a file
-Blaise

Similar Messages

  • Using a CWM format XML as datastore; COM SDK to read the file and create Universe

    Hello everyone
    We are in the process of migrating from a metadata store to BusinessObjects Universe and the plan is to use Java/COM SDK to accomplish that. We have run into limitations with both the SDKs. Java SDK doesn't provide that facility and using COM SDK we are trying to read from a XML file (metadata in CWM format) and create the universe but so far haven't been successful. If the (Universe)Designer can read a CWM format xml file (say created from BODS) we are wondering why can't a customer made COM program do the same.
    Has anyone attempted this and been successful. Please acknowledge.
    Thanks

    I have written C#.NET code to build universes on the fly using the Designer SDK with no problems.  However, I wasn't using CWM formatted data to do this.
    I have two suggestions for you:
    1.  Since not all of the functionality in the Designer tool seems to be available through the SDK, can you parse the CWM xml file in your code and build the universe based on the data instead of trying have Designer build it?
    2.  Since you're using Java, you may get better answers by posting this question in the Java SDK Application Development space here:  http://scn.sap.com/community/bi-platform/java-sdk
    -Dell

  • Document to formatted XML file

    I have a question. I have written a sample java program that will create an xml file. The program works properly, but the generated xml is not formatted. How can i format the xml file.
    The java program code is
    package com.spi.xml;
    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.TransformerFactory;
    import javax.xml.transform.dom.DOMSource;
    import javax.xml.transform.stream.StreamResult;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    public class WriteXML {
    static Document document;
    public static void buildDOM() {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    try {
    DocumentBuilder builder = factory.newDocumentBuilder();
    document = builder.newDocument();
    Element root = (Element) document.createElement("GUI");
    document.appendChild(root);
    Element curElement = document.createElement("Button");
    curElement.appendChild(document.createTextNode("Submit"));
    root.appendChild(curElement);
    curElement = document.createElement("Button");
    curElement.appendChild(document.createTextNode("Cancel"));
    root.appendChild(curElement);
    // Save the document to the disk file
    TransformerFactory tranFactory = TransformerFactory.newInstance();
    Transformer aTransformer = tranFactory.newTransformer();
    Source src = new DOMSource(document);
    Result dest = new StreamResult(new File("C:\\xmlFileName.xml"));
    aTransformer.transform(src, dest);
    } catch (Exception pce) {
    pce.printStackTrace();
    public static void main(String[] args) {
    buildDOM();
    The output (XML file)
    <?xml version="1.0" encoding="UTF-8"?>
    <GUI><Button>Submit</Button><Button>Cancel</Button></GUI>
    How can i format the xml file for multiple lines? I cant't use other libraries (Xerces,JDOM,Xalan) cause they are to big - the application is an applet.

    I don't think the DOM stuff in the core API provides any pretty printing facilities, unless they were added in 5.0.
    I know that jdom does--http://www.jdom.org
    You might also check out apache's XML stuff--http://xml.apache.org/
    Or dom4j--http://www.dom4j.org/

  • I have written a binary file with a specific header format in LABVIEW 8.6 and tried to Read the same Data File, Using LABVIEW 7.1.Here i Found some difficulty.Is there any way to Read the Data File(of LABVIEW 8.6), Using LABVIEW 7.1?

    I have written a binary file with a specific header format in LABVIEW 8.6 and tried  to Read the same Data File, Using LABVIEW 7.1.Here i Found some difficulty.Is there any way to Read the Data File(of LABVIEW 8.6), Using LABVIEW 7.1?

    I can think of two possible stumbling blocks:
    What are your 8.6 options for "byte order" and "prepend array or string size"?
    Overall, many file IO functions have changed with LabVIEW 8.0, so there might not be an exact 1:1 code conversion. You might need to make some modifications. For example, in 7.1, you should use "write file", the "binary file VIs" are special purpose (I16 or SGL). What is your data type?
    LabVIEW Champion . Do more with less code and in less time .

  • How to write non-XML data to a file using an OSB FTP Routing?

    Hi --
    Situation ... I need to write non-XML data to a file using FTP. A proxy service retrieves XML and transforms it with XSLT to CSV format, then gives it to a Biz service to file it out, using FTP. Simple.
    Problem ... OSB sends the contents of $body to any service it calls. Because $body is a SOAP document, it has to contain XML. So therefore I have to put my CSV data into an XML element, in order to put it into $body; and this inner element then gets written to the file, which I don’t want. But if I don't enclose my CSV content in a tag, I get "Unexpected CDATA encountered" trying to assign it to a variable.
    There has to be away around this!
    Thanks for your help.
    John Taylor

    Solved. Steps:
    -- Transform the XML to CSV using an XSL transform. Put the CSV data inside enclosing XML elements, and use a Replace action to put the XML element + CSV contents back into *$body*.
    -- Define an MFL transform that only knows about the enclosing XML elements. Use a delimiter of "\n" (hard return).
    -- Route from the proxy service to a Biz service that has Service Type = Messaging Service and Request Message Type = MFL; specify the MFL transform, which will receive the incoming *$body* variable, strip off the enclosing XML element within it, and pass the CSV contents to the FTP service.
    Edited by: DunedainRanger on Nov 29, 2011 9:03 AM

  • Appending XML data to a file using file adaptor

    Hi,
    I am trying to append data to a file using file adaptor in XML format. (Objective is to store data as XML message in the file). I understand it is possible to append data to an existing file by making appropriate changes in WSDL manually. However, my issue is every time the XML data is appended to a file even the XML header message is also getting appended. As a result the file data does not adhere to defined schema structure anymore.
    Is there a way to save XML data in a file in append mode ?
    Thanks, Riz

    I am having the same issue as well, which makes the output XML an invalid one. I have an XSD that has a hierarchy of elements. whenever I am wiriting the child elements the header message & the name space is also getting written. For example
    <?xml version="1.0" ?><Parent xmlns="http://testSchema.com/outputSchema">
    <StartDate>01/01/2001</StartDate>
    <EndDate>01/30/2001</EndDate>
    <Child/>
    </Parent>
    <?xml version="1.0" ?><Child xmlns:ns1="http://testSchema.com/outputSchema">
    <ns1:Id>20012981</ns1:Id>
    <ns1:Value/>
    <ns1:Date>01/15/2001</ns1:Date>
    </Child>
    <?xml version="1.0" ?><Child xmlns:ns1="http://testSchema.com/outputSchema">
    <ns1:Id>20012981</ns1:Id>
    <ns1:Value/>
    <ns1:Date>01/15/2001</ns1:Date>
    </Child>
    I am using a onefile adapter partnerlink to write the parent & an another one for writing the child element, since the child elements will repeat more than once. One other way to fix this issue is write the data using java embedded activity, but that would need a lot of boiler plate code, for writing/reading/appending the same file & for handling all those IOexceptions & buffer IN/outs. I am curious if someone had the same issue & how they resolved it.

  • How to create an Excel file from XML in the Receiver File Adapter Comm Ch

    How do I create an Excel file from XML in the Receiver File Adapter Communication Channel? I have my mapping done and I am outputting the file as a comma delimited csv file. However, the target can only process an Excel file (.xls). How can I generate an Excel in XI?
    I saw this blog, but I don't know how to create a XSLT transformation.
    /people/michal.krawczyk2/blog/2005/12/10/xi-generating-excel-files-without-the-java-nor-the-conversion-agent-not-possible
    Any help would be appreciated. Thanks.

    Here are the steps I took to create an XSLT transformation in XI 3.0:
    1. I created my source and target XSDs using XMLSpy.
    2. I created the XSLT mapping from source to target in XMLSpy (referencing the souce XSD schema).
    3. I created another XSLT mapping to format the target into Excel XML.
    4. Import the source and target XSDs in the IR's External Definitions
    5. Zip each XSLT mapping (.xls) and import it into the IR's Imported Archives
    6. Reference the XSL mappings in the Interface Mapping

  • How to convert IDoc-XML to native Idoc-File with in SAP XI/PI

    Hello,
    I have a problem to Create an native IDoc-Format for an File-Receiver.
    The scenario:
    I get an Idoc (ZMATMAS) from a SAP System to an MATMAS-exchange-scenario. One of the non-SAP-receiver-systems needs an other native IDoc-Format as File. So I have to map the ZMATMAS to the receiver Format and write this as File. The problem is, that this file contains the data as IDoc-XML and not as native IDoc-format.
    Has anybody an idea for this problem?

    U need to use sender idoc adapter and file receiver adapter.
    U can do file content conversion at receiver end.
    Content Conversion is basically to convert a text file that contains complex structures into an XML source format and vice versa. It is present only in the File Adapter because it is one of the message protocol which will convert the structure to a desired format.
    There are many blogs for File Content Conversion. Some of them are listed hereunder:-
    Introduction to simple(File-XI-File)scenario and complete walk through for starters(Part1)
    Introduction to simple (File-XI-File)scenario and complete walk through for starters(Part2)
    How to send a flat file with various field lengths and variable substructures to XI 3.0
    Content Conversion (Pattern/Random content in input file)
    NAB the TAB (File Adapter)
    File Content Conversion for Unequal Number of Columns
    Content Conversion ( The Key Field Problem )
    The specified item was not found.
    You may also check the FCC documentation for Sender and Receiver:-
    http://help.sap.com/saphelp_nw04/helpdata/en/2c/181077dd7d6b4ea6a8029b20bf7e55/content.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/d2/bab440c97f3716e10000000a155106/content.htm

  • How to fix iframe issue that displays XML values instead of formatted XML in IE11

    The following sub.jsp file shows the formatted XML properly as expected when is opened directly:
    <% response.setContentType("text/xml"); %>
    <book>
    <chapter1>chapter 1</chapter1>
    <chapter2>chapter 2</chapter2>
    </book>
    IE11 shows the result as below which are colored and can be collapsed or un-collapsed:
    <book><chapter1>chapter 1</chapter1><chapter2>chapter 2</chapter2></book>
    But if the sub.jsp is opened in an iframe from the below main.html, it only shows the values of the XML in the iframe:
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="ISO-8859-1">
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
    <iframe src="sub.jsp"></iframe>
    </body>
    </html>
    The iframe shows only the XML values, i.e., chapter 1 chapter 2 in IE11. This issue does not happen in IE8.
    I appreciate to your if you know how to address this issue.
    Regards, Amir

    The following sub.jsp file shows the formatted XML properly as expected when is opened directly:
    <% response.setContentType("text/xml"); %>
    <book>
    <chapter1>chapter 1</chapter1>
    <chapter2>chapter 2</chapter2>
    </book>
    IE11 shows the result as below which are colored and can be collapsed or un-collapsed:
    <book><chapter1>chapter 1</chapter1><chapter2>chapter 2</chapter2></book>
    But if the sub.jsp is opened in an iframe from the below main.html, it only shows the values of the XML in the iframe:
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="ISO-8859-1">
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
    <iframe src="sub.jsp"></iframe>
    </body>
    </html>
    The iframe shows only the XML values, i.e., chapter 1 chapter 2 in IE11. This issue does not happen in IE8.
    I appreciate to your if you know how to address this issue.
    This issue is also posted at below link:
    https://social.msdn.microsoft.com/Forums/en-US/5b0692b4-d312-4797-9089-42c1029ac059/how-to-fix-iframe-issue-that-displays-xml-values-instead-of-formatted-xml-in-ie11?forum=iewebdevelopment
    Regards, Amir

  • How to send a Material Idoc in format XML to SQL Server DB?

    Hi,
    I am creating a Material Idoc in format XML and I need send the same to a SQL Server DB.
    In the transaction BD10 I create the XML Idoc, but the same is stored in the SAP Server and I need send this to an external SQL Server DB.
    Somebody knows how to send automatically the XML Idoc to a SQL Server DB?
    Thanks and regards!
    Edited by: marcosap on Nov 11, 2010 4:00 PM

    Hi,
    All your XML idoc will get store in App layer,you can ask your Unix expert to write the unix code to fetch these XML idoc files and transfer to destination based on time period set by conjob.
    This is simple & easy job for any UNIX expert.
    Regards
    Siva

  • How to change Un formatted XML to Formatted XML in SSRS ?

    Hi Friends,
    I have an issue with SSRS report when exporting it into xml , it's showing un formatted xml like below
    but my requirement is it has to show formatted xml like below
    Please help me with this issue,
    NOTE: here i am building reports on Cube.
    Thanks in advance.
    Naveen

    Hi NaveenMSBI,
    By default, the XML rendering extension does not display formatted textbox values. In this case, we can use the UseFormattedValue device information setting to make the XML rendering extension display textbox values formatted the same way they are formatted
    in report viewer or report designer preview.  When UseFormattedValue is set to true, the formatted value is used instead.
    You can specify UseFormattedValue directly on the URL against the ReportServer endpoint or in a SOAP request. This can also be configured as the default for all XML rendering extension by editing the RSReportServer.config file. 
    For the details, please refer to the links as follows:
    Passing Device Information Settings to Rendering Extensions
    XML Device Information Settings
    Hope this helps.
    Regards,
    Heidi Duan
    Heidi Duan
    TechNet Community Support

  • Writing XML Object to a File

    Hi, I am using InDesign JavaScript to make an XML object in memory. When my script is done, I want to write the XML to a file. When I run the code below, the file is created, but the XML is not written to the file. Any help would be appreciated. Thanks. Rick
    #target indesign
    var partsMap = <partsMap />;
    savePartsMap (partsMap);
    function savePartsMap (partsMap) {
        var partsFile;
        // Make a File object for the parts map XML file.
        partsFile = new File("E:\\Test.xml");
        // Open the map file.
        partsFile.open("w");
        partsFile.write(partsMap);
        partsFile.close();

    Add partsFile.encoding = 'UTF-8'; right after your File instantiation.
    I'm not sure but you also might want to write partsMap.toXMLString() instead of the partsMap.toString() you're implicitly writing.
    Jeff

  • Finder data not being written to .DS_Store file

    The symptom of the problem I am experiencing is that the position of icons on my desktop (as well as icons in other folders in my home directory, as well as Finder window settings for folder in my home directory) are lost every time I log out. On a subsequent login, all of the icons "reflow" starting from the top right corner of the screen, just below the boot volume icon. I have been able to determine that this has to do with the .DS_Store file(s) in the Desktop folder and other folders of my home directory. If a .DS_Store file exists, the timestamp does not change when I change the icon layout and logout. If I delete the .DS_Store file, it is not re-created.
    In my case, my home directory (and the child Desktop folder) is being mounted off an SMB share on a Windows 2003 server. My Mac is using AD authentication to the same Windows 2003 server, which is the domain controller. I'm logging in with my AD credentials, and my home directory mapping is picked up from the home directory field in AD.
    Now, Googling this problem, I found a lot of people complaining about wanting to suppress the use/creation of the .DS_Store files on Windows network volumes. This led to an Apple KB article (http://support.apple.com/kb/HT1629) on how to modify a default to prevent the creation of .DS_Store files on network volumes--essentially the very behavior I am experiencing. The upshot of the KB article is to us the following command in terminal:
    *defaults write com.apple.desktopservices DSDontWriteNetworkStores true*
    I did a 'defaults read' to confirm this default isn't set on my install of Mac OS X 10.5.6--and it isn't. I then tried using the following variation in the hope I could force the behavior I wanted:
    *defaults write com.apple.desktopservices DSDontWriteNetworkStores false*
    Predictably, this had to effect.
    The upshot is, NONE of the Finder data for files and folders in my home directory (icon positions, Finder view window defaults, etc.) is preserved between logons. And this is driving me nuts! I've spent several hours over the past two evening trying to troubleshoot this, and I've had no luck.
    As a footnote, I'll mention that if I drag a folder from my home directory onto the local hard disk, the .DS_Store file is created/updated and things behave as expected (icon position and Finder window defaults are preserved). But, if I then drag the folder back over to my home directory, the values in the .DS_Store file become "frozen" and don't change.

    Hey, try this:
    1.
    Put a file in a folder on your Desktop.
    Edit: not your Desktop, but rather a typical local home on an HFS+ volume ~/Desktop
    2.
    Use "Get Info" to add a "Comment".
    The comment can be up to somewhere between 700 and 800 characters.
    3.
    Copy the folder to a FAT formatted flash drive, SMB share, etc.
    4.
    Create a new folder on the flash drive.
    5.
    Move the file from the first folder to the second folder.
    Confirm that the "Finder" shows the comment to be there.
    6.
    Quit the "Finder" - in 10.4 and earlier, this action would ensure that all .DS_Store files get updated, including transfer of comments. I.e. don't "relaunch" or "kill", etc. Enable and user the "Quit" menu, or use:<pre>
    osascript -e 'tell application "Finder" to quit</pre>
    7.
    Now where's the comment?
    In step 2, you could also have just created a file on the non-HFS volume and wasted your time typing in a 700 character comment.
    In step 6, a more real-world scenario is ejecting the drive or logging out, but deliberately quitting the "Finder" is the most conservative way to ensure that changes get written to .DS_Store files and comments survive. In 10.5.6, even under these conditions, comments are lost.
    Icon positions and view preferences are one thing, but with comments - that's real user-inputted data that Apple is playing fast and loose with. And if they no longer support comments on non-HFS volumes, the "Finder" shouldn't be showing you the comments when you double-check them in step 5, or allow them to be added in the alternate version of step 2.
    ..."C'mon Apple... what gives here?"...
    Unfortunately, this "Discussions" site is not frequented by Apple devs. Have you considered filing a bug report? I wonder what they would tell you, eg. if the treatment of .DS_Store files actually does turn out to be a bug or is intentional as it suspiciously seems...
    http://developer.apple.com/bugreporter/index.html

  • Export table to formatted xml

    I have an oracle table i have to export as formatted xml
    I really want the data to look like this : (and need to get rid of the cdata)
    <?xml version='1.0' ? XML_DATE = "2012-06-26 08:12:09 PM">
    <APPLICATION NAME = "XMLTESTING">
         <WEBPAGE>
              <PROJECT>
    <column1>ABC</column1>
    <column2>DEF</column2>
    <column3>GHI</column3>
    <column4>JKL</column4>
    <column5>MNO</column5>
    </PROJECT>
    <PROJECT>
    <column1>ABG</column1>
    <column2>DRF</column2>
    <column3>GLY</column3>
    <column4>JAL</column4>
    <column5>MPO</column5>
    </PROJECT>
    <PROJECT>
    <column1>BBC</column1>
    <column2>GEF</column2>
    <column3>LHI</column3>
    <column4>JCL</column4>
    <column5>MWO</column5>
    </PROJECT>
    </WEBPAGE>
    </APPLICATION>
    create table "XML_TESTING" (
    "column1" varchar2(50byte),
    "column2" varchar2(50byte),
    "column3" varchar2(50byte),
    "column4" varchar2(50byte),
    "column5" varchar2(50byte)
    INSERT into XML_TESTING values ('ABC','DEF','GHI','JKL','MNO');
    INSERT into XML_TESTING values ('ABG','DRF','GLY','JAL','MPO');
    INSERT into XML_TESTING values ('BBC','GEF','LHI','JCL','MWO');
    CREATE TABLE xml_cl(result CLOB);
    DECLARE
    ctxqry DBMS_XMLGEN.ctxHandle;
    result CLOB;
    BEGIN
    ctxqry := dbms_xmlgen.newContext('SELECT * FROM xml_testing');
    DBMS_XMLGEN.setRowTag(ctxqry,'APPLICATIO NAME = "XML TESTING"');
    --DBMS_XMLGEN.setMaxRows(ctxqry,5);
    DBMS_XMLGEN.setrowsettag(ctxqry,'WEBPAGE');
    LOOP
    result := DBMS_XMLGEN.getXML(ctxqry);
    EXIT WHEN
    DBMS_XMLGEN.getNumRowsProcessed(ctxqry)=0;
    INSERT INTO xml_cl VALUES(result);
    END LOOP;
    END;
    SELECT * FROM xml_cl
    THEN I EXPORT TO XML FROM HERE.
    this is how xml currently looks
    <?xml version='1.0' encoding='Cp1252' ?>
    <RESULTS>
         <ROW>
              <COLUMN NAME="RESULT"><![CDATA[<?xml version="1.0"?>
    <WEBPAGE>
    <APPLICATIO_x0020_NAME_x0020__x003D__x0020__x0022_XML_x0020_TESTING_x0022_>
      <column1>ABC</column1>
      <column2>DEF</column2>
      <column3>GHI</column3>
      <column4>JKL</column4>
      <column5>MNO</column5>
    </APPLICATIO_x0020_NAME_x0020__x003D__x0020__x0022_XML_x0020_TESTING_x0022_>
    <APPLICATIO_x0020_NAME_x0020__x003D__x0020__x0022_XML_x0020_TESTING_x0022_>
      <column1>ABG</column1>
      <column2>DRF</column2>
      <column3>GLY</column3>
      <column4>JAL</column4>
      <column5>MPO</column5>
    </APPLICATIO_x0020_NAME_x0020__x003D__x0020__x0022_XML_x0020_TESTING_x0022_>
    <APPLICATIO_x0020_NAME_x0020__x003D__x0020__x0022_XML_x0020_TESTING_x0022_>
      <column1>BBC</column1>
      <column2>GEF</column2>
      <column3>LHI</column3>
      <column4>JCL</column4>
      <column5>MWO</column5>
    </APPLICATIO_x0020_NAME_x0020__x003D__x0020__x0022_XML_x0020_TESTING_x0022_>
    </WEBPAGE>
    ]]></COLUMN>
         </ROW>
    </RESULTS>
    hope someone can help.
    did alot of searching and reading and just cant find an answer
    thank you

    Use SQL/XML functions to build and serialize the document as CLOB in a single query :
    SQL> SELECT XMLSerialize(document
      2           XMLElement("APPLICATION",
      3             XMLAttributes('XMLTESTING' as "NAME")
      4           , XMLElement("WEBPAGE",
      5               XMLAgg(
      6                 XMLElement("PROJECT",
      7                   XMLForest("column1", "column2", "column3", "column4", "column5")
      8                 )
      9               )
    10             )
    11           )
    12           as clob
    13           indent --< for formatting purpose only
    14         )
    15  FROM xml_testing
    16  ;
    XMLSERIALIZE(DOCUMENTXMLELEMEN
    <APPLICATION NAME="XMLTESTING">
      <WEBPAGE>
        <PROJECT>
          <column1>ABC</column1>
          <column2>DEF</column2>
          <column3>GHI</column3>
          <column4>JKL</column4>
          <column5>MNO</column5>
        </PROJECT>
        <PROJECT>
          <column1>ABG</column1>
          <column2>DRF</column2>
          <column3>GLY</column3>
          <column4>JAL</column4>
          <column5>MPO</column5>
        </PROJECT>
        <PROJECT>
          <column1>BBC</column1>
          <column2>GEF</column2>
          <column3>LHI</column3>
          <column4>JCL</column4>
          <column5>MWO</column5>
        </PROJECT>
      </WEBPAGE>
    </APPLICATION>
    Then you can call DBMS_XSLPROCESSOR.CLOB2FILE to write the CLOB to a file, no need of an intermediate table.

  • How to best format input read from a file to a string

    I am trying to set up a class to convert input read from an xml-file to a java-string, which I can pass on to a web service.
    My attempt is probably not the smartest, but what I did was to set up a for-loop, which iterates through each line in the xml, appending "\n" to the end of each line, before storing them in a variable, which is loaded into an arraylist. When there are no more lines to read in the xml-file, the for-loop should terminate and the contents of the ArrayList should be written to a string, which is then returned.
    Below is my attempt to implement this - thanks in advance!
    import java.io.*;
    import java.util.*;
    public class RequestBuilder {
         private String _filename, output;
         //Constructor method
         RequestBuilder(String filename){
              String line;
              _filename = filename;
              //Sets up a array to store each line of XML read from a file
              ArrayList<String> lineList;
         lineList = new ArrayList<String>();
              try {
                   //Sets up a filereader and a buffer
                   FileReader fr = new FileReader(_filename);
                   BufferedReader br = new BufferedReader(fr);
                   //Iterates through each element of the arraylist until empty
                   for (String o : lineList){
                   //Stores a single linein a variable and appends a line-break
                   line = br.readLine() + "\n";
                   //Addseach line to the arraylist
                   lineList.add(line);
                   //Closes the filereader
                   fr.close();
                   //Writes the arraylist to a string
                   output = lineList.toString();
              } catch (FileNotFoundException e) {
                   e.printStackTrace();
              } catch (IOException e) {
                   e.printStackTrace();
         public String getRequest(){
              return output;
    }

    799992 wrote:
    Well, the reason for doing an ArrayList was that I had to process each line with line breaks and escape characters, but I know realize that I can do the same thing by summing the lines for each iteration directly intro a string like below - it works :-)
    Apparently the filereader takes care of double-quotes as I don't see any difference in the output when I disable the logic I made, which substitutes " with \", can anyone confirm this?
    The code I ended up using:
         //Sets up a filereader and a buffer
                   FileReader fr = new FileReader(_filename);
                   BufferedReader br = new BufferedReader(fr); 
                   //initializes the output variable with the first line from the file
                   output = br.readLine() + "\n";
                   while (br.ready() == true) {
                        //reads each line, saves it in a variable and appends line breaks
                        line = br.readLine() + "\n";
                        //Replaces adds escape character to any double-quotes (apparently not neccessary?)
                        tmpLine = line.replaceAll("\"", "\\\"");
                        line = tmpLine;
                        //sums each line in the current string
                        output = output + line;
    As EJP said you can directly write to the webservice. If you want to check for yourself what the result looks like just read the file without adding anything.
    public String readFile(){
         String xmlString = "";
              try{
                   String line = null;
                   xmlFile = new File(//file);
                   reader = new BufferedReader(new FileReader(xmlFile));
                        while((line = reader.readLine()) != null){
                             xmlString += line;
              catch(FileNotFoundException e){
                        e.printStackTrace();
              catch(IOException e){
                        e.printStackTrace();
         return xmlString.replaceAll("\\s+"," ").trim();//remove spaces
    }

Maybe you are looking for