Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can someone help me out with these? It did not give any xml class, this is the o

ID: 3723855 • Letter: C

Question

Can someone help me out with these? It did not give any xml class, this is the only thing it gives

luppearg(NaturaINumber n, int digit) 8. Complete the body of one return statement. it satisf ongestText so it satisfies its contract. For full credit, you must use recursion and only * Reports the text of the longest plain text node in the XMLTree t. @param t the XMLTree * @return the text of the longest plain text node in t * @requires [t has at least one plain text node] * @ensures longestText [the text of the longest plain text node in t) private static String longestText (XMLTree t) t

Explanation / Answer

(8) Ans :

Programming code :

import java.io.*;

import java.util.*;

import org.jdom2.*;

import org.jdom2.input.SAXBuilder;

public class LongestTextFinder {

  

   private static String longestText(Element t) {

       String lt = "", temp;

       Element ele;

       if (t.getChildren().size() > 0) {

           ListIterator<Element> l = t.getChildren().listIterator();

           while (l.hasNext()) {

               ele = l.next();

               temp = longestText(ele);

               if (lt == null || lt.isEmpty()) lt = temp;

               else {

                   if(lt.length() < temp.length()) lt = temp;

               }

           }

       } else {

           lt = t.getValue();

       }

//       System.out.println("lt is " + lt);

       return lt;

   }

public static void main( String args[]) throws JDOMException, IOException {

      File inputFile = new File("XTree.xml");

       SAXBuilder saxBuilder = new SAXBuilder();

       Document document = saxBuilder.build(inputFile);

       Element root = document.getRootElement();

       String answer;

       answer = longestText(root);

       System.out.println("The longest text is : " + answer);

   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote