Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

jdom question

Posted on 2006-06-21
7
Medium Priority
?
291 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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 will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

610 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