?
Solved

jdom question

Posted on 2006-06-21
7
Medium Priority
?
289 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
7 Comments
 
LVL 10

Accepted Solution

by:
mukundha_expert earned 100 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 100 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses
Course of the Month10 days, 12 hours left to enroll

765 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