Solved

jdom question

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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…
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now