Formatting problem with JDOM

friends,
help me out plz..
While creating a xml document using JDOM ,
I am not able to get the formatted xml file.
program output is:
<?xml version="1.0" encoding="UTF-8"?>
<person><name>A</name><name>B</name><name>C</name><name>D</name></person>
I want the result as:
<?xml version="1.0" encoding="UTF-8"?>
<person>
     <name>A</name>
     <name>B</name>
     <name>C</name>
     <name>D</name>
</person>
// XMLGenerator.java
import org.jdom.Element;
import org.jdom.Document;
import org.jdom.output.XMLOutputter;
import java.io.*;
public class XMLGenerator {
public static void main(String[] args) throws Exception{
Element root = new Element("employee");
while(rs.next()) // rs .. ResultSet
Element emp_name= new Element("name");
emp_name.setText(rs.getString(rs.getString("name")));
root.addContent(emp_name);
Document doc = new Document(root);
// serialize it into a file
try {
FileOutputStream out = new FileOutputStream("record.xml");
XMLOutputter serializer = new XMLOutputter();
serializer .setIndent(true);
serializer.output(doc, out);
out.flush();
out.close();
catch (IOException e) {
System.err.println(e);

try:
XMLOutputter serializer = new XMLOutputter( " " );
with the size of the indent you require.
You dont really need the line: serializer.setIndent(true); if u use this constructor.
Hope this Helps
Sam

Similar Messages

  • Smartform: Formatting Problem with QUAN-Field

    I want to print a smartform and get exception 1 (formatting error). With function SSF_READ_ERRORS I get an error table. There is on entry: errnumber = 020011, msgid = SSFCOMPOSER, msgty = E, msgno = 601, msgv1 = wa_outtab-menge.
    It seems to be a formatting problem with field WA_OUTTAB-MENGE. But in the structure this field is referenced correctly.
    Does anybody know a solution?

    I solve this kind of problem in my SmartForm.
    Try this:
    Go to "Global Definitions" Node, then "Current/Quant.Fields" tab and set these values:
    Field Name:      WA_OUTTAB-MENGE
    Reference Field: WA_OUTTAB-MEINS
    Data Type:       QUAN
    Best Regards,
    Eduardo Ribeiro.

  • Whatsnew page for 3.6.17 has formatting problems with Firefox and I.E.

    I just updated from 3.6.16 to 3.6.17n and the whatsnew page, displayed after Firefox restarted, has formatting problems in the lower right hand corner.
    I checked it with I.E. 8 and it also shows the formatting problem.
    Why wasn't this caught before the page was put into "production"?
    The URL is http://www.mozilla.com/en-US/firefox/3.6.17/whatsnew/
    There is a line with the text "Release Notes » Firefox Features » Firefox Help »" that is being displayed on top of other material.
    I wonder what a new Firefox user or an inexperienced user would think of this? They might think that they did something wrong or, worse, they might consider Firefox had problems and they won't use it.
    This reflects badly on Firefox.
    One more thing, could someone make this textarea taller and wider. It is so small as to cause problems typing and proofing the material.
    The URL is https://support.mozilla.com/en-US/questions/new?product=desktop&category=d6&search=whatsnew+page+for+3.6.17+has+formatting+problems+with+Firefox+and+I.E.&showform=1
    How about upping the cols and rows values? They are currently rows="10" cols="40"

    As you have a Power Mac you also have a alternative option to consider which is a third-party build from http://tenfourfox.blogspot.com/2011/08/601-now-available.html

  • Intresting problem with JDOM and xmlns in root element.

    Hi all,
    I am trying to parse a xml file using a jdom java code.This code works fine if I remove xmlns attribute in the root element.Please tell me how to fix this issue.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Xml
    <process name="CreateKBEntryService" targetNamespace="http://serena.com/CreateKBEntryService" suppressJoinFailure="yes" xmlns:tns="http://serena.com/CreateKBEntryService" xmlns="http://schemas.xmlsoap.org/ws/2003/03/business-process/" xmlns:bpelx="http://schemas.oracle.com/bpel/extension" xmlns:ora="http://schemas.oracle.com/xpath/extension" xmlns:nsxml0="http://localhost:8080/axis/services/CreateKBEntryService" xmlns:nsxml1="http://DefaultNamespace" xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/">
    <partnerLinks>
              <partnerLink name="client" partnerLinkType="tns:CreateKBEntryService" myRole="CreateKBEntryServiceProvider"/>
              <partnerLink name="CreateKBEntryPartnerLink" partnerLinkType="nsxml0:CreateKBEntryLink" partnerRole="CreateKBEntryProvider"/>
         </partnerLinks>
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
    Java:
    import java.io.*;
    import java.util.*;
    import org.jdom.Document;
    import org.jdom.Element;
    import org.jdom.input.SAXBuilder;
    public class sample1 {
    public static void main(String[] args) throws Exception {
    // create a XML parser and read the XML file
    SAXBuilder oBuilder = new SAXBuilder();
    Document oDoc = oBuilder.build(new File("file location "));
         Element root = oDoc.getRootElement();
         System.out.println(root.getName());
         String tgtns= root.getAttributeValue("targetNamespace");
         System.out.println("tgt ns "+ tgtns);
    List list= root.getChildren("partnerLinks");
         Iterator it1= list.iterator();
         System.out.println(list.size());
         while(it1.hasNext()){
              Element partnerlinks = (Element)it1.next();
              List list2= partnerlinks.getChildren("partnerLink");
              System.out.println(list2.size());
              Iterator it2= list2.iterator();
              String[][] partnerLinkval = new String [2][list2.size()];
              int i=0,j=0;
              while(it2.hasNext())
                   Element el2= (Element)it2.next();
              String ElementName = el2.getName();
              partnerLinkval[i][j]= ElementName;
              j++;
              String Attribute = el2.getAttributeValue("myRole");
              partnerLinkval[i][j]= Attribute;
              i++;
              j--;
              System.out.println("Saving in array "+el2.getName());
              System.out.println("Saving in array "+Attribute);
              System.out.println("array length"+partnerLinkval.length);
              for (int l=0;l<2;l++){
              for(int k=0;k<partnerLinkval.length;k++)
                   System.out.println(partnerLinkval[l][k]);
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Result:
    Without Xmlns in xml file
    process
    tgt ns http://serena.com/buildserviceflow
    1
    2
    Saving in array partnerLink
    Saving in array BpelServiceFlowProvider
    Saving in array partnerLink
    Saving in array null
    array length2
    partnerLink
    BpelServiceFlowProvider
    partnerLink
    null
    Result with xmlns:
    process
    tgt ns http://serena.com/CreateKBEntryService
    0

    Hi,
    I am also having the same problem using jdom, my code works fine when there is no xmlns attribute but when i put the xmlns attribute back in doesn't work.
    Did you manage to find a way to solve this problem?

  • Problems with JDOm XPath

    Hi all.
    I have a JDOM XML document and I use JDOMXPath to apply XPath expressions on the XML document.
    I have XPath expression for which JDOMXPath does not match any node:
    //*[not(count(descendant::a) < 4)]
    [not(descendant::node()[count(descendant::a)>3])]
    [not(descendant::text()[normalize-space(string())!='']
    [not(ancestor::a)])]
    XML parser such as Saxon, MSXML, etc. correctly match this XPath on the document and find the appropriate node-set, so the XPath expression is 100% right from the XPath syntax perspective.
    But in JDOM, it does not match.
    Could anybody tell me what is the problem?
    Thank you very much for help and sorry if this is the wrong place to ask this question - this is my first post here.
    Thanks again,
    Anna

    Sorry, forgot to tell something very important:
    the XML node-set that I am trying to match is as follows:
    <ul>
    <li>Accessibility</li>
    <li>Amaya</li>
    <li>ABC</li>
    <li>CC/PP</li>
    </ul>
    The interesting moment is, that if I change the node-set to look like this:
    <ul><li>Accessibility</li><li>Amaya</li><li>ABC</li><li><a href="Mobile/CCPP/"></a></li></ul>
    i.e. without any spaces, JDOMXPath will match for the above XPath.
    Is there any problem with spaces in JDOM/JDOMXPath?
    Thanks again
    Anna

  • Format problem with MSI 865Neo2-PFISR

    I had a problem with my MSI 865Neo2-PFISR, when i was formatting the drive (WD 40GB 7200) format it was not responding... by thw way... i completed the format with the 4th try, and before 2 wks i have format again and everything it was fine. But why it was not responding at the first format?
    i have Celeron 2.4Ghz northwood
    MSI 865Neo2-PFISR
    Kingston 256 DDR400
    WD 40GB 7200rpm
    Abit ATi 9200SE-DT 128MB
    SoundBlaster AudigyES

    I had the same PSU noname 350W and i formatted my disk fine, just 3 times it stops to respond at the first time, now i have levicom PSU with 28A on 3.3V and it's ok...

  • Data format problem with Write to Spreedsheet File

    I have a problem with the data format with Write to spredsheet file.
    I have an N*3 array, where the 3 elements in each row should has different length. When I used Write to spreedsheet file,
    it can only save the three data in one format. How can I save them in the format of "%0.8f %0.3f %0.2f"?
    Thanks for your help.

    Hi powerplay,
    another solution may be to convert column-wise using "number to fractional string", then interleaving resulting arrays and again using "array to spreadsheet string" (with "space" as separator).
    Many ways lead to Rome
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • Formatting problem with windows XP

    Hmmm... I have several older macs that I'm currently using for parts for both my G4 and my PC. The problem I'm having is with the HDDs. I've removed several internal IDE hard drives (from 3.2 to 15 GB) all of which are formatted for mac OS9.1 extended. They work great in my G4 but my PC (windows XP professional) won't even recognize them and I can't re-format them in DOS on my mac because that option isn't available in drive setup..
    Do I need a third party program (either mac or PC and what would you recommend) or is there someway to work around this? I would hate to just throw them out because they do work
    I realize this isn't critical but it is a bit of a pain and any help would be appreciated.
    G4   Mac OS 9.1.x  

    Thanx again Tom!
    The only problem with Swissknife is that it only works on drives that are already recognized by the PC. I can't even get these guys to show up, let alone mount! I even have a USB to IDE connection so I can attach them externally. It works great on my PC formatted HDs but still won't register my mac ones..
    by the way, I tried your idea with OS9 and it still won't let me format in DOS
    Is a puzzlement..

  • Problem with JDOM and schemas

    I'm trying to parse (and validate) an XML document with JDOM.
    My root element is declared in the schaema whixh is asociated to the document.
    But during parsing, an exception saying that my root element is not declared is thrown.
    Can someone axplain to me what can happen ?
    Thank's

    What's this element ?
    My schema is indicated by the xsi:schemeLocation attribute of my root-element .

  • HT201071 RAW format Problem with NIKON D600 after updating to maverick.

    We still have problems after this update.
    Pictures in RAW format imported to Aperture are brilliant as they are with the NIKON D600. Imported Pictures with the NIKON D800 are aweful. They are kind of grey without any saturation. To convert every single Picture to JPEG brings back their brilliance and colors. We have consulted the apple and the aperture support, but they dind't have any solution to fix our issue.
    Any ideas?

    Have you also asked in the Adobe forums?  To have people read your post, best not to include long crash reports until asked to do so.

  • Problem with JDOM and euro character

    Hi,
    I have an xml file including euro characters (�) and starting with :
    <?xml version="1.0" encoding="ISO-8859-15"?>
    as it should probably be.
    However, my problem is that (JDOM and) SAXBuilder doesn't recognize the euro characters and replace them by an unknown character '?'.
    What's wrong and how can I solve it?
    Thanks in advance.

    All right, this is a a part of my code:
    ....SAXBuilder builder = new SAXBuilder( true );
    //create the document
    //this doc contains this tag <RefVersion> data�data </RefVersion>
    Document doc = builder.build( "E:\\test.xml" );
    System.out.print( "before charAt = " + "�".charAt(0) + String.valueOf('\u20ac') );
    String str = "euro�euro";
    System.out.println( "euro�euro ->" + str.replace('\u20ac','O') );
    Element root = doc.getRootElement();
    //recup du noeud RefVersion
    Element version = root.getChild( "RefVersion" );
    str = version.getText();
    System.out.println( "nom= " + version.getName() + " data= " + str );
    System.out.println( "index de � ds euro�euro " + str.replace('\u20ac','O') );
    and the output is:
    before charAt = ��
    euro�euro ->euroOeuro
    nom= RefVersion data= data?data
    index de � ds euro�euro data?data
    So, obviously, it comes from JDOM.

  • Problems with JDom

    In my Jdom program I got the following errors during compilation. It could compile on one machine,
    but it did not on another,even though I made sure the machines are set up properly:
    package com.sun.java.util.collections does not exist
    import com.sun.java.util.collections.*;
    ^
    file com\sun\java\util\collections\List.class not found
    outputter.output(jdomDocument, new FileOutputStream(outputfilename));
    ^
    2 errors
    Same thing with running it. I could run it on one machine, but not another:
    Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/java/util/collections/Collection
    at org.jdom.input.DefaultJDOMFactory.document(DefaultJDOMFactory.java)
    at org.jdom.input.DOMBuilder.build(DOMBuilder.java)
    at org.bcit.mmsd.lab5.MyJDOMParser.<init>(MyJDOMParser.java:86)
    at org.bcit.mmsd.lab5.Controller.<init>(Controller.java:77)
    at org.bcit.mmsd.lab5.Controller.main(Controller.java:135)

    I've a similar problem. With this code:
    import org.jdom.*; // version 8 beta
    import org.jdom.input.*;
    public static void listChildren(org.jdom.Element current) {
    java.util.List children = current.getChildren();
    Iterator iterator = children.iterator();
    while (iterator.hasNext()) {
    Element child = (Element) iterator.next();
    listChildren(child);
    compiled on NetBeans 3.4, I've got this error:
    incompatible types:
    found : com.sun.java.util.collections.Iterator
    required: java.util.Iterator
    Iterator iterator = children.iterator();
    ????????

  • Formatting problems with document

    Ok I've made an estimate form in pages and put a table in it.  Adding a table has done a lot of odd things to the document. I can't change the spelling on any words inside the table. It will hightlight them as incorrect but I'm unable to change the spelling using my mouse for suggestions. I can change it manually if I can figure out how to spell the word.
    But here are my real problems, please see attached screenshot. 
    1) In the line total column it won't allow me to put a period after the dollar amount. I put it there and it keeps removing it!
    2) I can't line up the text in the 2 columns. Because when I put in the $640. where I want it to be (using return key) once I finish putting in the number it puts it at the top of the column.  I can't keep it down by the text "Labor and Materials".  As you can see by the red underline I had to put in text there and make it white so it won't show up to move the $640. down.
    Can someone tell me how to fix these 2 issues??
    Any help would be greatly appreciated.
    Susan

    Hi!
    I would use cells with the same height. I would only write one line in each cell, at least for the ones that will have a number in the next cell to the right. You really don't need a  punctuation after the number. I have used the formatting options in the Inspector. I have changed the cell borders for some cells to none (see the second image). I do this on Snow Leopard, not on Lion like you have. The spelling correction problem must someone else test. It works on my computer to right click on the misspelled word

  • Numeric Format problem with 0 value

    I have a numeric column in a Webi report.  There are some values showing a 0.  My customer doesn't want the 0 value to be shown, instead of it she wants the dash sign ( - ) to be shown, just like in Ms Excel.
    I do right-click on the column and choose Number Format.  Then I choose Number and any of the formats shown in the list.  Then I check the Custom option. In the Equal to Zero box  I input a dash sign because I want this sign  -  to be shown instead of the 0 values.  But it doesn't work.  Instead of the dash it shows a blank cell.
    What can I do to solve this problem? Is it a bug in Business Objects XI?

    >
    salah1 wrote:
    > Another way of doing this is in the universe designer, you can right click on dimension/measure, choose object format and then in the number format add \- in the 'Equal to Zero' box. This way you dont have to add formula in each report.
    >
    > Edited by: salah1 on Sep 7, 2010 11:28 AM
    Thanks for your post!
    I was wrong when using the Format Number option in WebI because I was putting just the dash sign and with your post now I know that I had to use a backslash sign like you mention \- , instead of just placing in the  'Equal to Zero' box this - sign.
    So it works not only in Universe Designer but in WebI too.

  • Numerical Characters Formatting Problem With XML Report Output Run From Command Line

    Hi,
    Problem description is:
    When a BI Publisher concurrent job is submitted as a child job of a PL/SQL type concurrent request, the locale in OPP is not set same as of RTF template selected. This results in number format and date format localization not work as expected. For example, when BI Publisher child job is submitted after attaching RTF template (through fnd_request.add_layout API) having language-territory as de-DE, the number format on PDF output comes out as 9,999.00 instead of 9.999,00.
    Points to notice:
    1. In OPP log we noticed that xslt._XDOLOCALE always has value EN-GB irrespective of language-territory of attached RTF template
    2. NLS_NUMERIC_CHARACTER column in fnd_concurrent_request table has no value for BI Publisher job. We can set it up through fnd_request.set_options API but it is not a desired solution. We need that OPP should automatically choose correct number format depending on locale of selected RTF template
    3. When same child BI Publisher job's output is re-processed through "XML Publisher Report" program and de-DE locale is chosen for RTF template then the number format localization works fine.
    Please help us to understand root cause of this issue and how it can be resolved.
    Thanks!

    Hi,
    Problem description is:
    When a BI Publisher concurrent job is submitted as a child job of a PL/SQL type concurrent request, the locale in OPP is not set same as of RTF template selected. This results in number format and date format localization not work as expected. For example, when BI Publisher child job is submitted after attaching RTF template (through fnd_request.add_layout API) having language-territory as de-DE, the number format on PDF output comes out as 9,999.00 instead of 9.999,00.
    Points to notice:
    1. In OPP log we noticed that xslt._XDOLOCALE always has value EN-GB irrespective of language-territory of attached RTF template
    2. NLS_NUMERIC_CHARACTER column in fnd_concurrent_request table has no value for BI Publisher job. We can set it up through fnd_request.set_options API but it is not a desired solution. We need that OPP should automatically choose correct number format depending on locale of selected RTF template
    3. When same child BI Publisher job's output is re-processed through "XML Publisher Report" program and de-DE locale is chosen for RTF template then the number format localization works fine.
    Please help us to understand root cause of this issue and how it can be resolved.
    Thanks!

Maybe you are looking for

  • Deleting custom paper sizes

    I have created too many custom paper sizes and now making a selection has gotten confusing.  How do I delete the ones I no longer use? Thanks, Biscuit

  • Printer driver s for Canon i70

    I have a G4 powerbook and I also have a Canon printer i70 and it has been used a bit when I travel - on various computers. I want to add it to this Powerbook but I cannot find a driver on the web. Lots of efforts to sell me driver doctor and so on, a

  • Fileout was not working properly?

    Hi dudes iam new to shake... after watching the Video tutorials which came with the software... i tried some of the workes but u know it took long time for me finish 50% perfect work finally... but at the end iam trying to watch some of tutorials in

  • Drop down menus for iWeb?

    Can you get or build drop-down menus for iWeb?

  • Using ISR2800 as H320 Gateway?

    Hi I'd like to hear if anyone is really using an ISR2800 as an ISDN gateway to connect to other companies. I've tried my best to follow the guidelines in http://www.cisco.com/en/US/docs/video/milticomm/h320Bonding.html#wp1260005 but I cannot make it