   | Mailing List | | Home | | Forum Home | | JBoss - Java Application Server | | Struts - A MVC web framework | | Tomcat - JSP/Servlet container | | iText - An open source PDF Java Library | | JDOM - JDOM XML Parser | | J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition | | J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog | | Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology | | JSP - A mailing list about Java Server Pages specification and reference | |
Struts & Hibernate
|
|
|
  | |  | Creating multiple Elements | Creating multiple Elements 2004-01-12 - By Moipone Mocoancoeng
Back
In my program I?m quiring the database for an activity then check the array of activities activity[6] if the activity exist in the array, if it does exist I then copy the activity into another array new_activity[6]. If the activity value already exist in the new_activity array I don?t copy the value.
Now I need to create an XML doc using the values in the new_activity array with the outcome like the following.
<ActivitySummary>
<Activity> Training </Activity>
<Activity>Certification</Activity>
</ActivitySummary>
Here?s my code
String actType = activity.getChild("Activity").getText();
String[] activity = {"Training", "RPL","Assessment", "Certification","CPD", "EEP" };
String new_activity[] = new String[6];
for(int i = 0; I < activity.length; i++){
if(actType ==activity[i]){
if(actType!= new_activity[i]){
new_activity[i] = actType;
}
}
if(act[a]!=null){
Element activityS = new Element("ActivitySummary");
Element activityT = new Element("Activity");
activityT.setText(new_activity[i]);
activityS.addContent(activityT);
XMLOutputter outputter = new XMLOutputter();
outputter.output(activityS, System.out);
}
}
The result I get are as follows
<ActivitySummary>
<Activity> Training </Activity>
</ActivitySummary>
<ActivitySummary>
<Activity>Certification</Activity>
</ActivitySummary>
How will I create this Activity element in a way that they?ll are multiple element to the ActivitySummary element.
Best Regards
-- ---- ---- ---- ---- ---- ----- Do you Yahoo!? Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman">In my program I?m quiring the database for an activity then check the array of activities activity[6] if the activity exist in the array, if it does exist I then copy the activity into another array new_activity[6]. If the activity value already exist in the new_activity array I don?t copy the value.</FONT></P > <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman">Now I need to create an XML doc using the values in the new_activity array with the outcome like the following.</FONT></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman">< ;ActivitySummary></FONT></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman"> <SPAN style="mso-tab-count: 1"> </SPAN><Activity> Training </Activity></FONT></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman"> <SPAN style="mso-tab-count: 1"> </SPAN><Activity>Certification</Activity></FONT>< /P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman">< ;/ActivitySummary></FONT></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p><FONT face="Times New Roman"> </FONT></o:p></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman" >Here?s my code</FONT></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p><FONT face="Times New Roman "> </FONT></o:p></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman" >String actType = activity.getChild("Activity").getText();<o:p></o:p></FONT></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman" >String[] activity = <SPAN style="mso-spacerun: yes"> </SPAN>{"Training", "RPL","Assessment", "Certification","CPD","EEP" };</FONT></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman" >String <SPAN style="mso-spacerun: yes"> </SPAN>new_activity[] = new String [6];</FONT></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman">for (int i = 0; I < activity.length; i++){</FONT></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman"> <SPAN style="mso-spacerun: yes"> </SPAN>if(actType ==activity[i]){< /FONT></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman"> <SPAN style="mso-tab-count: 1"> </SPAN>if(actType!= new_activity[i]){</FONT></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman"> <SPAN style="mso-tab-count: 2"> </SPAN>new_activity[i] = actType;</FONT></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman"> <SPAN style="mso-tab-count: 1"> </SPAN>}</FONT></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman"> <SPAN style="mso-spacerun: yes"> </SPAN>}</FONT></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman"> <SPAN style="mso-spacerun: yes"> </SPAN>if(act[a]!=null){<o:p></o:p></FONT>< /P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman"> <SPAN style="mso-spacerun: yes"> </SPAN>Element activityS = new Element( "ActivitySummary");<o:p></o:p></FONT></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman"> <SPAN style="mso-spacerun: yes"> </SPAN>Element activityT = new Element( "Activity");<o:p></o:p></FONT></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman"> <SPAN style="mso-spacerun: yes"> </SPAN>activityT.setText(new_activity[i]); <o:p></o:p></FONT></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman"> <SPAN style="mso-spacerun: yes"> </SPAN><SPAN style="mso-spacerun: yes"> < /SPAN>activityS.addContent(activityT);<o:p></o:p></FONT></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman"> <SPAN style="mso-spacerun: yes"> </SPAN>XMLOutputter outputter = new XMLOutputter();<o:p></o:p></FONT></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman"> <SPAN style="mso-spacerun: yes"> </SPAN>outputter.output(activityS, System .out);<o:p></o:p></FONT></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman"> <SPAN style="mso-spacerun: yes"> </SPAN>}<SPAN style="mso-tab-count: 1"> </SPAN><SPAN style="mso-tab-count: 1">  ; </SPAN></FONT></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman">}< /FONT></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p><FONT face="Times New Roman "> </FONT></o:p></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman">The result I get are as follows</FONT></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman"><EM ><ActivitySummary></EM></FONT></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman"><EM ><SPAN style="mso-tab-count: 1"> </SPAN><Activity> Training </Activity></EM></FONT ></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman"><EM ></ActivitySummary></EM></FONT></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman"><EM ><ActivitySummary></EM></FONT></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman"><EM ><SPAN style="mso-spacerun: yes"> </SPAN><SPAN style="mso-tab -count: 1"> </SPAN><Activity> ;Certification</Activity></EM></FONT></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman"><EM ></ActivitySummary></EM></FONT></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p><FONT face="Times New Roman "> </FONT></o:p></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman">How will I create this Activity element in a way that they?ll are multiple <SPAN style="mso-spacerun: yes"> </SPAN>element to the ActivitySummary element.< /FONT></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p><FONT face="Times New Roman "> </FONT></o:p></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><FONT face="Times New Roman" >Best Regards</FONT></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p><FONT face="Times New Roman "> </FONT></o:p></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p><FONT face="Times New Roman "> </FONT></o:p></P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"><o:p><FONT face="Times New Roman "> </FONT></o:p></P> <P> </P><p><hr SIZE=1> Do you Yahoo!?<br> Yahoo! Hotjobs: <a href="http://pa.yahoo.com/*http://us.rd.yahoo.com/hotjobs /mail_footer_email/evt=21482/*http://hotjobs.sweepstakes.yahoo.com/signingbonus" >Enter the "Signing Bonus" Sweepstakes</a>
Earn $52 per hosting referral at Lunarpages.
|
|
 |