Solved

jdom question

Posted on 2006-06-21
7
284 Views
Last Modified: 2010-03-31


hi all can you use jdom to return xml in this format


<parent id="" title="" type="">
  <child1>xxxxxx</child1>
  <child2>xxxxxx</child2>
  <child3>xxxxxx</child3>
</parent>


I have jdom working if i want them all as attributes e.g.or all as tags but not a mixture of both

many thanks

0
Comment
Question by:dalecon
  • 2
7 Comments
 
LVL 10

Accepted Solution

by:
mukundha_expert earned 25 total points
ID: 16953366
Ya you can do that, try this code,
you will get your XML


<parent id="id" title="title" type="type">
  <child1>xxxxxx</child1>
  <child2>xxxxxx</child2>
</parent>


Document doc = new Document () ;
Element root = new Element ( "Parent" ) ;
            
doc.addContent( root ) ;
            
root.setAttribute( "ID","id") ;
root.setAttribute( "Type","type") ;
root.setAttribute( "Title","title") ;
            
Element child1 = new Element ( "Child1" ) ;
child1.addContent( "XXXXX" ) ;
      
Element child2 = new Element ( "Child1" ) ;
child2.addContent( "XXXXX" ) ;

0
 
LVL 6

Assisted Solution

by:phuocnh
phuocnh earned 25 total points
ID: 16956315
Element root = new Element ( "Parent" ) ;
  root.setAttribute( "ID","id") ;
  root.setAttribute( "Type","type") ;
  root.setAttribute( "Title","title") ;
 Document doc = new Document (root);
 Element child1 = new Element ( "child1" ) ;
child1.addContent( "XXXXX" ) ;
 doc.getRootElement().getChildren().add(child1);
Element child2 = new Element ( "child2" ) ;
child2.addContent( "XXXXX" ) ;
 doc.getRootElement().getChildren().add(child2);
//XMLOutputter out = new XMLOutputter();
 //out.setFormat(Format.getRawFormat().setOmitEncoding(true));
 //System.out.println(out.outputString(doc));
Phuoc
0
 

Author Comment

by:dalecon
ID: 16960745


I've sorrted this using a method like this

    public void setAsAttribute(String columnName, String attribName)
    {
        String name = columnName.toLowerCase();
       
        attributes.put(name, "t");
       
        newNames.put(name, attribName);
    }

in my jdom class
0
 
LVL 10

Expert Comment

by:mukundha_expert
ID: 16960909
what actually you want to do??

post your code
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Maven Project: Hibernate Dependencies Conflict 10 40
how to add new optional parameter to JSP 1 49
java jdbc batch example 8 41
Java: The Public Class Main 4 32
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to implement Singleton Design Pattern in Java.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question