Format XML data when writing 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?

Also, I am planning on using xpath in conjunction with DOM. However I read on one of the websites not to use too many xpath queries. I am using jdk 1.5.
Is it tight. My code might have to be run many times. Is the following ok?
or should I eliminate xpath and do my own traversing. I am concerned about runtime performance if I have to continue to update the xml file frequently.
public Element getMatchingNode(MyAttributes attr) throws Exception {
try {
File myFile = new File(XMLFile);
if (myFile.exists()) {
System.out.println(XMLFile + " File exists");
XPathFactory factory = XPathFactory.newInstance();
XPath xPath = factory.newXPath();
InputSource inputSource =
new InputSource(new FileInputStream(myFile));
String matchingString = this.getMatchingString(attr);
Element module =
(Element)xPath.evaluate("/" + TEST_TAG +
"/" +
TEST_TAG2 +
"/" +
DETAIL +
matchingString,
inputSource,
XPathConstants.NODE);
return module;
} else
return null;
} catch (Exception x) {
throw x;
private String getMatchingString(MyAttributes attrs){
StringBuffer buffer = new StringBuffer();
for (Enumeration e=attrs.keys(); e.hasMoreElements();){
String attribute = (String)e.nextElement();
String value = attrs.get(attribute);
buffer.append("[@" + attribute + "=" + "'" + value + "']");
return buffer.toString();
}

Similar Messages

  • Error when Writing Metadata to Files in Bridge (Mac) but not in Bridge (PC)

    We get an error when writing metadata to files in Bridge (Mac) but not in Bridge (PC). In the same drive and folder, the PC can successfully write a keyword to a file on the PC, where the Mac returns an error. I have researched this at the Adobe Knowledgebase, but their answer seemed to indicate it was a global issue, and we don't see that behavior on the PC.
    The client is a Mac of course, and the server volume is a Windows share volume. The Mac is bound to AD, and the domain\username and username formats have both been tried when logging in, but you receive the error in both.
    Any help would be appreciated.
    Thanks!
    Rich Oliver

    Hi, I'm having the same problem using FreeNAS (which uses Samba and Netatalk in the backend), but I tried with both AFP and SMB on Mavericks and Yosemite, I still have the same issue.  I think it might be a timing issue with how lightroom interact with a slower write delay using network shares.  I suggest you also chime into this thread:  Lightroom 5 can't write metadata to DNG files   I really hope this is resolved as this is impacting my productivity as I moved my workflow to my Macbook with a shared NAS.

  • Errors when writing metadata to files on Windows Server

    Good day!
    I have an iMac running OSX 10.9 (Maverick) and Lightroom 5.2.
    My catalog is on the local iMac drive, and the images are on SMB shared drive (handled by Windows 2012 server).
    I decided to do the final layout of my album using InDesign, and for that I needed to access to images using Bridge. So selected all the images (the rated once...) and issue a Metadata/Save command.
    The system came back with errors on many of the files (such as Photos are read only, and unknown errors).
    Retrying to save the metadata on image that was flagged with an error usually (but not always) worked.
    I tried to select save the metadata for few (6) images in a time, many times it was ok, but sometimes, one or two of them failed (and retrying again usually solved the problem).
    It looks to me like a timing related issue.
    Any ideas?
    (After spending about an hour on this, I have exported the images to my local drive...). In general I don't have similar problems with other apps.
    Any ideas?
    Yuval

    I Yuval
    I'm experiencing more or less the same behavior (see Read-only error when writing metadata to file over network (Synology DS1315+ using AFP) ). For me however, the problem is more pronounced if I use the AFP protocol and is better (I think as you described) if I use SMB (all done on a Synology DS1315+). With SMB it most often works but in very rare cases I also get the "read only" message!
    Do you have solution to this? Or are you stuck as I am?
    Cheers, Chris

  • Can I find the date when I transferred some files to someone else's pc?

    Hi, have a MacBook Pro but don't really know how to use it!
    I need to find out the date when I transferred some files to someone else's computer. Is there an area with some sort of history of actions where I can see what I did?
    thanks for any help
    M

    (Woggledog, I think the OP is trying to find out the date the files were copied from the Mac, not to the Mac.)
    If you are trying to determine when you transferred the files +without access to the PC that they were transferred to+, you are out of luck, I'm afraid. There's no log for that information. If you can access the PC the files were transferred to, the created/accessed dates on the PC will reflect the move. But I suspect you can't access that computer, which is why you're seeking a log of some sort...
    How did you move the files? If you used a flash drive, for example, and still have that, check there...even if the files were deleted from the drive, they may be recoverable.
    Hope this helps...

  • Square in front of data when writing to file

    When I gather up a bunch of strings in a while loop, after I write the data to a file, the first line always has 3 spaces followed by a square. What is happening and is there a workaround to the problem.
    I included sample code of what Im trying to accomplish, essentially, the while loop has a string concantanation for each line in the file I am trying to write to, everything works great but the darn square problem is putting a damper on my progress.
    Any help is greatly appreciated!!
    Thanks
    David
    Attachments:
    autotune_wingy_fix.vi ‏70 KB

    Hi David,
    I think your problem could come from your way of writing into the file. It's better to write a string than an array of strings into a file.
    Try to convert your array into a single string and write it to the file.
    I've attached an LV6.1 Version of your VI modified.
    Hope this helps !
    Julien
    Attachments:
    autotune_wingy_fix[1].vi ‏65 KB

  • XML data (Output) into a flat file

    I need to convert XML data into a flat file, which is having "|" as delimiter and ftp the same to a server. The XML data is an output of BPEL activity. The XML data is employee records. Each employee records should come as one line in the flat file.
    Is it possible to do this? if so, what will be the steps
    Thanks

    Hi,
    You need to use file adapter to write your XML payload as a flat file.
    Following are the steps to write XML payload into a flat file:
    1. Create a sample flat file and add few rows in which fields should be delimited with pipe symbol. See the record sample given below:
    Name|Age|Address|City|State|Zip
    Sam|32|2788 Viking Dr|Green Bay|WI|54304
    Here first row is the header row, you can remove the header row if it is not required.
    2. Create a file adapter service using adapter configuration wizard. Give file name and folder location where you want to write flat file. On step 5 of the adapter configuration wizard you have to define or select message schema. Click on Define Schema for Native Format button, then Native Format Builder Wizard will be opened, here you can define message schema for your flat file.
    2.1 Here you need to select Delimited for file type.
    2.2 Give details about your flat file, select your sample flat file here, which you have created in step 1 above.
    2.3 Click Next button twice and go to step 4, here give namespace and element names you want and click on Next.
    2.4 In step 5 you need to specify delimiters. Wizard doesn’t shows *|* as a delimiter so you need to enter *|* in the Delimited By combo box and click on Next button.
    2.5 Complete remaining steps and click on Finish in the wizard.
    3. Finish "Adapter Creation Wizard". Add BPEL activities (assign, invoke) to pass XML payload to file adapter and file adapter will generate *|* delimited flat file and write it to the given folder.
    See the following article for more details on Native Format Builder Wizard:
    http://download-uk.oracle.com/docs/cd/B31017_01/integrate.1013/b28994/nfb.htm#CCHCIGCA
    Regards,
    Dharmendra
    http://soa-howto.blogspot.com

  • Java input xml data and xsl template -output file excel

    i need help or same special link on web.
    i must develop code or use a special tool that make this.
    INPUT:
    xml that contain real data
    xsl that explain a report template
    OUTPUT:
    file excel that show the template xsl with xml data source
    thank for help me.

    Hi,
    Please refer to "Oracle XML Publisher User's Guide".
    Applications Releases 11i and 12
    http://www.oracle.com/technetwork/indexes/documentation/index.html
    This is also explained in the document attached in (Publishing Concurrent Requests with XML Publisher [ID 295409.1]).
    Thanks,
    Hussein

  • Controlling the share permission when writing a text file

    I have several application that writes a delimited text file to a file share.  Another application, not a LabVIEW application then reads the delimited text file.  When my application is creating and/or writing to the delimited text file, is there a way to manipulate the permissions so that no other application can read the file at the same time I'm writing to the file?  I can do this in Visual Basic via the FileShare (http://msdn.microsoft.com/en-us/library/system.io.fileshare(v=vs.110).aspx) option when creating filestream, but I don't see this option in LabVIEW.  Thanks.
    Solved!
    Go to Solution.

    Nevermind.  I believe this can be accomplished with the "Deny Access" function.

  • Attach the whole form with XML data when Emailed

    Hi all
    I am new to Adobe Livecycle product. I have been using IBM workplace forms and now want to migrate to Adobe Forms. I want the whole completed PDF form to be attached along with the xml data in it when someone clicks the email button and email is sent. Currently when I am able to attach only the data part to the email.
    Please advice on this...
    Thanks
    Ullas

    The default email submit button is set up to send just the data/ If you drop a button object onto the form, set it to be a submit button, then use the mailto protocol to setup who you want to send it to. One of the button parameters allows you to choose what you want to submit. in your case choose PDF.

  • Why do I get a NI-488 error massage when writing into a file and at the same time copiyng this file with a backup softwarre like Easy2Sync?

    I have a small LabVIEW program which writes random numbers very fast into a ASCII-file. I want that file to be copied to a new position every 10 min. Therefor I use a backup/synchronisation software which is doing a copy operation every 10 min. It works fine a certian amount of time and after a while I get either an LabVIEW error (LabVIEW: Fiel already open: NI-488 Comand requieres GPIB Controller to be System controller) or an backup-software error (couldn´t open file...whatever). I´m guessing, it has something to do with file-access but I don´t know why?!? If I run the LabVIEW program and I copy and paste the random-number-file with the windows explorer very fast (pressing ctrl+v rapidly) while LabVIEW is still writing into this file, no error appears. Can sombody help me?
    LabVIEW 2011

    Hi Serdj,
    you don't get a GPIB error, the error number has just 2 different explanations...
    Well, you have two programs accessing the same file. One program just wants to make a copy, the other (LabView) is trying to write to the file. When copying a file that is written to you get inconsistent results! That's why one of both programs is complaining an error...
    You can't have write and read access at the same time! (But you can have more than one read access at the same time...)
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • "Deep data objects not supported" when writing into a file

    Hello everybody,
    I am having some issues about a program that i made which puts the content of any table in a file that i created.
    The problem is when my table (transparent table) has a deep data type in it (example : a string field, so with undefined length).
    Here is my code :
      DATA : lt_gentable TYPE REF TO data.
      DATA : ls_gentable TYPE REF TO data.
      FIELD-SYMBOLS : <ft_lines> TYPE STANDARD TABLE.
      FIELD-SYMBOLS : <fs_line> TYPE ANY.
      CREATE DATA lt_gentable TYPE TABLE OF (p_tab).
      CREATE DATA ls_gentable TYPE (p_tab).
      "creation of links
      ASSIGN ls_gentable->* TO <fs_line>.
      ASSIGN lt_gentable->* TO <ft_lines>.
      DATA : l_fname     TYPE char80.
      CONCATENATE '\dir\dir2\' l_fname_log INTO l_fname.
      OPEN DATASET l_fname FOR OUTPUT IN BINARY MODE.
      OPEN CURSOR WITH HOLD l_c FOR SELECT * FROM (p_tab).
      DO.
        FETCH NEXT CURSOR l_c INTO TABLE <ft_lines> PACKAGE SIZE p_size.
        IF sy-subrc = 0.
          LOOP AT <ft_lines> INTO <fs_line>.
            TRANSFER <fs_line> TO l_fname.   <=====> GOES INTO DUMP BECAUSE MY TABLE (p_tab) has a string field
          ENDLOOP.
          CLEAR <ft_lines>.
        ELSE.
          CLOSE CURSOR l_c.
          EXIT.
        ENDIF.
      ENDDO.
      CLOSE DATASET l_fname.
    Here is the message i am getting :
    At the statement
       "TRANSFER f TO ..."
    no deep data objects are supported at the a
    for strings.
    Elementary deep data types are internal tabl
    data object) references and strings (STRING,
    General deep data objects are elementary dee
    that contain deep data objects.
    In this particular case, the operand "f" has
    internal identification "v".
      List of internal ABAP types:
      C    Text (Character)
      N    Numerical text
      D    Date (YYYYMMDD)
      T    Time (HHMMSS)
      X    Hexadecimal
      I    Integer
      P    Packed number
      F    Floating point number
      h    Internal table
      r    Object reference
      l    Data reference
      g    String of type C
      y    String of type X
      s    2-byte integer with plus/minus sign
      b    1-byte integer without plus/minus sig
      u    Structure (flat structure)
      v    Structure (deep structure)
    Can you help me to go through this issue ?
    Any kind of help would be appreciated.
    Christian

    Sandra is correct I agree with him,
    TRANSFER dobj TO dset [LENGTH len]
                          [NO END OF LINE].
    dobj must be character-type . Use String.
    Please read the F1 help for the TRANSFER Statement and also please check the example
    In your case assign the <fs> to Casting File asfollows
    DATA: file TYPE string VALUE `flights.dat`,
          wa TYPE spfli.
    FIELD-SYMBOLS TYPE x.
      ASSIGN wa TO CASTING.
      TRANSFER TO file.
    Hope this helps...

  • Formating xml data

    am importing xml from a xml attribute and storing it as a
    string. I am then loading it into a dynamic text box with render as
    html on. The problem is formating only part of the data in the
    dynamic text field as Italics or bold. I'm unable to put any
    <>brackets inside the xml attribute so that it would then
    render in the dynamic text field as html. I've tried using entities
    and decimal equivalents as a substitute for the html mark up with
    no success. How do I formate the xml node attribute with italics
    and bold.
    Example
    <Slides>
    <slideNode titlezText="This the
    <i>Title</i>"></slideNode>
    </slides>
    This wont display. How do I italicize the word "title" when
    it is inputed into a dynamic text field.

    Thanks, the problem is I was trying to add the html mark up
    to a xml node attribute, but it appears as tho I will have to make
    this information from the node attribute be put in a new node
    instead.

  • UTL_FILE write_error when writing large binary files to unix os

    I am trying to write large files to a folder in unix from a table containing a BLOB object. The procedure below is called by another procedure I have written to do this. It works in windows environment fine with files up to 360MB. When I run this exact same procedure in UNIX I get an initialization error. When I change the WB in the fopen call to W it works. I can store all the files I want up to 130MB in size. The next size larger file I have is 240MB and it fails after writing the first 1KB passing the utl_file.write_error message. If someone can help me to diagnose the problem, I would really appreciate it. i have been trying everything I can think of to get this to work.
    Specifics are, the windows version is 10GR2, on unix we are running on Sun Solaris 9 using 9iR2
    PROCEDURE writebin(pi_file_name IN VARCHAR2, pi_file_url IN VARCHAR2, pi_file_data IN BLOB)
    IS
    v_file_ref utl_file.file_type;
    v_lob_size NUMBER;
    v_raw_max_size constant NUMBER := 32767;
    v_buffer raw(32767);
    v_buffer_offset NUMBER := 1;
    -- Position in stream
    v_buffer_length NUMBER;
    BEGIN
    -- WB used in windows environment. W used in unix
    v_lob_size := dbms_lob.getlength(pi_file_data);
    v_file_ref := utl_file.fopen(pi_file_url, pi_file_name, 'WB', v_raw_max_size);
    v_buffer_length := v_raw_max_size;
    WHILE v_buffer_offset < v_lob_size
    LOOP
    IF v_buffer_offset + v_raw_max_size > v_lob_size THEN
    v_buffer_length := v_lob_size -v_buffer_offset;
    END IF;
    dbms_lob.READ(pi_file_data, v_buffer_length, v_buffer_offset, v_buffer);
    utl_file.put_raw(v_file_ref, v_buffer, TRUE);
    v_buffer_offset := v_buffer_offset + v_buffer_length;
    END LOOP;
    utl_file.fclose(v_file_ref);
    END writebin;
    Message was edited by:
    user599879

    check if this cample code helps -
    CREATE OR REPLACE PROCEDURE prc_unload_blob_to_file IS
    vlocation      VARCHAR2(16) := ‘LOB_OUTPUT’;
    vopen_mode     VARCHAR2(16) := ‘w’;
    bimax_linesize NUMBER := 32767;
    v_my_vr        RAW(32767);
    v_start_pos    NUMBER := 1;
    v_output       utl_file.file_type;
    BEGIN
    FOR cur_lob IN (SELECT vmime_type,
    blob_resim,
    vresim,
    dbms_lob.getlength(blob_resim) len
    FROM tcihaz_resim a
    WHERE rownum < 3 -- for test purposes
    ORDER BY a.nresim_id) LOOP
    v_output := utl_file.fopen(vlocation,
    cur_lob.vresim,
    vopen_mode,
    bimax_linesize);
    dbms_output.put_line(’Column length: ‘ || to_char(cur_lob.len) || ‘ for file: ‘ ||
    cur_lob.vresim);
    v_start_pos := 1;
    IF cur_lob.len < bimax_linesize THEN
    dbms_lob.READ(cur_lob.blob_resim,
    cur_lob.len,
    v_start_pos,
    v_my_vr);
    utl_file.put_raw(v_output,
    v_my_vr,
    autoflush => TRUE);
    dbms_output.put_line(’Finished Reading and Flushing ‘ || to_char(cur_lob.len) ||
    ‘ Bytes’ || ‘ for file: ‘ || cur_lob.vresim);
    ELSE
    dbms_lob.READ(cur_lob.blob_resim,
    bimax_linesize,
    v_start_pos,
    v_my_vr);
    utl_file.put_raw(v_output,
    v_my_vr,
    autoflush => TRUE);
    dbms_output.put_line(’Finished Reading and Flushing ‘ || to_char(cur_lob.len) ||
    ‘ Bytes’ || ‘ for file: ‘ || cur_lob.vresim);
    END IF;
    v_start_pos := v_start_pos + bimax_linesize;
    WHILE (v_start_pos < bimax_linesize) LOOP
    -- loop till entire data is fetched
    dbms_lob.READ(cur_lob.blob_resim,
    bimax_linesize,
    v_start_pos,
    v_my_vr);
    utl_file.put_raw(v_output,
    v_my_vr,
    autoflush => TRUE);
    dbms_output.put_line(’Finished Reading and Flushing ‘ ||
    to_char(bimax_linesize + v_start_pos - 1) || ‘ Bytes’ ||
    ‘ for file: ‘ || cur_lob.vresim);
    v_start_pos := v_start_pos + bimax_linesize;
    END LOOP;
    utl_file.fclose(v_output);
    dbms_output.put_line(’Finished successfully and file closed’);
    END LOOP;
    END prc_unload_blob_to_file;
    set serveroutput on
    set timing on
    create or replace directory LOB_OUTPUT as ‘/export/home/oracle/tutema/’;
    GRANT ALL ON DIRECTORY LOB_OUTPUT TO PUBLIC;
    exec prc_unload_blob_to_file ;
    Column length: 3330 for file: no_image_found.gif
    Finished Reading and Flushing 3330 Bytes for file: no_image_found.gif
    Finished successfully and file closed
    Column length: 10223 for file: OT311.gif
    Finished Reading and Flushing 10223 Bytes for file: OT311.gif
    Finished successfully and file closed
    PL/SQL procedure successfully completedWith 9iR2 PLSQL can write binary files using UTL_FILE put_raw function, prior to Oracle9iR2 you will need to create an external procedure with Java, C, VB or some 3gl language.
    Some references -
    http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:6379798216275
    Oracle® Database PL/SQL Packages and Types Reference 10g Release 2 (10.2)
    UTL_FILE - http://download-uk.oracle.com/docs/cd/B19306_01/appdev.102/b14258/u_file.htm#sthref14095
    http://psoug.org/reference/dbms_lob.html
    Metalink Note:70110.1, Subject: WRITING BLOB/CLOB/BFILE CONTENTS TO A FILE USING EXTERNAL PROCEDURES

  • Strange character appear when writing to text file.

    Hello, I am facing some problem when I read some data from and binary file (.dat) and then saving them into text file.
    When I convert those data into string and then write to a text file. Some strange characters were found in the file when I opened it with excel. Could anybody tell me how these strange characters( ) are generated and how to eliminate them?
    The VI , .dat file and the text file are attached as below.(use the "open file" in the menu to open .dat file and then use the "export file" in menu to export to text file)
    Thank you very much......
    The .dat and text file are attached in the next post.
    Attachments:
    test2.xls ‏1 KB
    VPSDataViewer_vac_temp2.vi ‏111 KB
    Sel_File.vi ‏20 KB

    raw data file.
    Thank you very much.
    the vpsxxxx.ini is the raw data(file with .dat extension cannot be attached).
    viewer.vi is the menu file. (please change the file name to viewer.rtm, also for attaching file purpose. ^_^)
    Attachments:
    VPS20070107_152605.ini ‏2 KB
    Viewer.vi ‏1 KB

  • Proper format of cells after Writing to csv file?

    I have been searching, yet struggling with what is probably pretty simple to do.  I am writing data to a csv but my data is not coming out the way I need it to look in the spreadsheet once its been written.  Each of the channel's data from the front panel need to be in their own Column.  Please see attached csv for what I'm aiming to accomplish in a finished program.  As of right now, I can write to the csv file but the data and fields are not in their proper columns/rows.  Can someone get me jump started on this please?  I'm very new and green in Labview.  This is my first program.  Thank you. 
    Solved!
    Go to Solution.
    Attachments:
    Front_Panel.vi ‏23 KB
    CSVdata.csv ‏1 KB

    It is recommended to turn on context help (ctrl+H) so you can get a brief description of stuff you mouse over.  You can get detailed information by clicking on "details".
    For example, you would have seen the terminal for "transpose" in the context window.  Curious to see what it did, you would have clicked on "details".  That would have shown you what "transpose" does.
    I hate it that Microsoft trains you to ignore help files because they write them so poorly.
    Bill
    (Mid-Level minion.)
    My support system ensures that I don't look totally incompetent.
    Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.

Maybe you are looking for

  • Macbook can't "read or write to disk" of ipod

    Just bought a new 30GB 5th Gen. ipod and loaded half of my music/photos onto it. Now it gives an error message every time I try to sync new albums about not being able to read or write to the ipod. Any suggestions? The updater download didn't seem to

  • Java console and forms builder ?

    hi all , i am using developer suite 10g rel2 , db 10g rel2 ,jinitiator 1.3.1.22 . every time i run a form , a java console opens on my windows task bar , and does not close when i close my browser or form . when i open windows task manager ctrl+alt+d

  • How Do I get the right patches from my keyboard into LOgic??

    Please help me. I'm a beginner of Logic. Can someone tell me how to record the sound that I want to record into the MIDI track?? When I click on the first track with the grand piano picture, and then play my keyboard, I dont hear grand piano but stri

  • How to access EBO Designer in AIA 3.0

    HI, I have installed AIA 3.0. But when i login , i only see CAVS, Project Lifecycle and Setup. How can i access EBO Designer? THanks Manish

  • Getting nested TransactionScopes working

    Hello, I'm using ODP.NET 2.111.7.20 and database 11.1.0.7.0 - 64bit. I'm trying something like this, only the insert method is in another DLL and the insert is a bit more complicated: Even if I didn't complete the root transaction the rows are insert