Solved

jdom question

Posted on 2006-06-21
7
283 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mockito example issue 8 73
javap bin 2 34
SHA2 certs for IIS AND Java? 2 93
What's wrong with this code? 4 23
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

809 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