How to add ElementHelper in to another ElementHelper?

I have to create Xml Response.In that i have structure something like  following?

<Element1>
   <ElementHelper1>
            <ElementhelperInside>   </ElementhelperInside>
  </ElementHelper1>
<Element1>

I did  like this:
Element Element1= new Element( "Element1" );

Element Ele1 = new Element( "ElementHelper1", DEFAULTNAMESPACE ) ;
       
     ElementHelper ElementHelper1= new ElementHelper(Ele1 );

Element Ele2 = new Element( "ElementhelperInside", DEFAULTNAMESPACE );
            ElementHelper ElementhelperInside= new ElementHelper(Ele2)
--Here i am adding  elements :But inside helper is not showing containts.

ElementHelper1.addElement(ElementhelperInside.data);
Element1.addContent( ElementHelper1.getData() );

                  
ANISHKA1Asked:
Who is Participating?
 
CEHJConnect With a Mentor Commented:
So for your last example, you need to call that twice on 'SubElement' for each of its children and once on 'Element' for 'SubElement' itself
0
 
CEHJCommented:
You need to append a child element. What API are you using?
0
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.

 
ANISHKA1Author Commented:
i am using JDom. Can you please explain me How?
0
 
ANISHKA1Author Commented:
I did almost same like which is in link.But i need to add subElement  inside Element which also has sub Elements:-
<MainElement>
   <Element></Element>
   <Element>
      <SubElement>
             <ele1></ele1>
             <ele2></ele2>
    </SubElement>
  </Element>
</MainElement>
0
 
CEHJCommented:
Try
ElementHelper1.addContent(ElementhelperInside);

Open in new window

0
 
ANISHKA1Author Commented:
ElementHelper doen't have addContents method.it has only addElement.
0
 
ANISHKA1Author Commented:
i did this and it added ElementHelperInside into ElementHelper1 but whatever into ElementHelperInside like subElements are missing.
ElementHelper1.addElement(ElementhelperInside);
0
 
CEHJCommented:
>>ElementHelper doen't have addContents method

http://www.jdom.org/docs/apidocs/org/jdom/Element.html#addContent(org.jdom.Content)

>>but whatever into ElementHelperInside like subElements are missing.

You need to do the same with the sub elements, as i mentioned earlier
0
 
CEHJCommented:
:-)
0
 
objectsCommented:
glad I could help :)
give me a yell if you need more assistance in the future.

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.