Erron while

Erron while

Hi, i'm doing a project regarding xml. I want to extract all nodes from body of existing xml doc to make another xml with that data.Here is my coding and error showing on that coding.Could anybody help to know my error? coding:

public class Test {
        public static void main(String[] args) throws Exception {
            String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><html> <body> <h1 align=\"center\">Profile</h1><hr /> <div class=\"centered\"> <table><tr><td><strong>Name: </strong></td> <td>A</td> </tr> <tr> <td><strong>Age: </strong></td> <td>23</td> <td>programmer</td></tr><tr><td><strong>Email: </strong></td><td>[email protected]</td></tr></table></div><hr /></body></html>";
            SAXBuilder builder = new SAXBuilder();
            Document doc = builder.build(new StringReader(xml));
            listChildren(doc.getRootElement(), 0);
        }
            //root=existing document's root element
           //body=new documents body    
        private static void listChildren(Element root, int depth) {
            System.out.println(root.getName());
            List<Element> children = root.getChildren();
            if (children == null || children.isEmpty())
                    return;
            for (Element child : children) {
                     System.out.println(child.toString());
                     body.addContent(child);
                     listChildren(child, depth+1);
            }

            return;
        }
    }

error shown:

html
1
[Element: <body/>]
org.jdom.IllegalAddException: The Content already has an existing parent "html"
    at org.jdom.ContentList.add(ContentList.java:209)
    at org.jdom.ContentList.add(ContentList.java:131)
    at java.util.AbstractList.add(Unknown Source)
    at org.jdom.Element.addContent(Element.java:811)
    at Test.listChildren(Test.java:86)
    at Test.main(Test.java:53)
View Answers









Related Tutorials/Questions & Answers:
Erron while
Erron while   Hi, i'm doing a project regarding xml. I want to extract all nodes from body of existing xml doc to make another xml with that data.Here is my coding and error showing on that coding.Could anybody help to know my
while and do while
while and do while  hello, What is the difference between a while statement and a do statement?   hello,ADS_TO_REPLACE_1 A while statement checks at the beginning of a loop to see whether the next loop iteration
Advertisements
While and do-while
While and do-while       Nested classes Here is another advantage of the Java, object-oriented programming language that allows us to define a class within another
The while and do
While and do-while       Lets try to find out what a while statement does. In a simpler language, the while statement continually executes a block of statements while
while & do..while Loop
while & do..while Loop while loop The while loop iterate until provided condition is true. Given below the syntax : while (condition)  ...; <?php $j=1; while($j<=3) { echo "Value of j" . $j . "<
While and do-while
While and do-while       Lets try to find out what a while statement does. In a simpler language, the while statement continually executes a block of statements while a particular
php do while syntax
php do while syntax  How to create a do while loop in php. What is the syntax
php do while example
php do while example  Simple example of do while loop in PHP
php do while loop
php do while loop  Difference between do while loop and simple loop in PHP
php while loop
php while loop  Example to fetch the data using while loop in PHP
While loop Statement.
While loop Statement.   How to Print Table In java using While Loop
The While keyword
The While keyword       While is a keyword defined in the java programming language. Keywords... programming language likewise the while keyword indicates the following
php array loop while
php array loop while  Using the php array while loop
reached end of file while parsing and while expected
reached end of file while parsing and while expected  import java.io.*; public class temperature{ public static void main(String []args)throws...); }while(result=='Y'); System.out.println("Thank you for using
php do while break
php do while break   receiving a Fatal saying cannot break/continue.. please suggest. Thank U
php do while false
php do while false   Is there any difference between FALSE and false
while loop to for loops
while loop to for loops  I have to change this while loops... to know how to change it. int currentNum= num1; while(num1>num2... Are: "); while(num1 <= num2) { if(num1%2 != 0) { System.out.print
Memory leak in While loop
Memory leak in While loop  How to manage a memory leak in While loop ?   make sure loop is not running infinitley. ------------------------------------ Chandraprakash Sarathe http://javaved.blogspot.com/   
while executing a java program
while executing a java program  while iam executing a simple java program after i type "java simple.java" there was a an error occuring.the error is "exception in thread "main" java.lang.noclassdeffounderror:simple" what thus
do-while loop
do-while loop  how many times will the following loop get executed and what will be the final value of the variable I after execution the loop is over. int I = 5; do{ I + = 3; System.out.println(""+I); I=I+1; }while(I>=9
While loop Statement
While loop Statement  How to print a table using while loop?   The given example displays the multiplication table of the given number... +" = "); while(y<=10) { int t = x
programes on while loop
programes on while loop   write a program to calculate sum of an entered digit write a program to find gcd and lcm of 2 positive integers   Java sum of digits Java Find LCM and GCD
While loop - Java Beginners
While loop  Given a number, write a program using while loop to reverse the digits of the number. Eg. the no. is 12345, should be written as 54321...(br.readLine()); int n=num; int rem=0; int rev=0; while(n!=0
While running jsp
While running jsp  I found this error when i run the client.jsp can anyone help me javax.xml.ws.WebServiceException: Failed to access the WSDL at: http://localhost:8080/WebService1/MyWebService?wsdl. It failed with: http
while loop handling
while loop handling  Dear deepak, thanks for your response yesterday.. I am doing a project on travelling domain.. in that initially i searched all... option the while loop always taking tyhe last flight datails only... and in all
While Loop with JOptionPane
While Loop with JOptionPane  Hello there, why the output only... int k = 5; String name; int age; while(i < k...[]=new String[5]; int arr[]=new int[5]; while(i < k){ String name
Character count by while loop
Character count by while loop  Write the program to count the number of characters entered until a full stop (.)is keyed-in. Anyone there pls help with this question...   import java.io.*; import java.util.*; class
While Loop
While Loop       Loop.... Loop makes your program readable, flexible and reliable. While loop: While loop... the statements or processes written under the while loop are executed otherwise ignored
java code using while loop
java code using while loop  
programes on do... while
to check at last time int check=0,remainder; while(num > 0){ remainder = num % 10
Class.forName will do while loading drivers
Class.forName will do while loading drivers  What Class.forName will do while loading drivers
while Java Keyword
while Java Keyword       The while is a keyword defined in the java programming language... to a compiler in java programming language likewise the while keyword indicates
How to write a loop and a while loop
How to write a loop and a while loop  How do I write a 1 loop and a 1 while loop for the example code: public boolean isTheFirstOneBigger (int num1, int num2) { if (num1 > num2) { return true
Iterator Java While
The Java While loop Iterator is the top tested loop. It is in two forms while(), do while() While loop is mostly used with Iterator compared to for loop Java While Loop Iterator Example import java.util.ArrayList; import
Java Break while example
Java Break while example     ... be used for terminating other loops as well such as while, do while etc. . Break... the while loop is demonstrated.  In the program we breaking while loop under
Do-while loop in Java
Do-while loop in Java In this section you will learn about do-while loop in Java. do-while loop is similar to while loop but the difference is do-while loop... condition repeatedly and run at least once. For that we need a do-while loop so
error while compiling - Java Beginners
error while compiling  i am facing problem with compiling and running a simple java program, can any one help me, the error i am getting is javac is not recognised as internal or external command  Check if you JAVA_HOME
Error While Compiling - Java Beginners
Error While Compiling  Hi All I Am a beginner and i face the following problem while compiling can anyone help me. C:\javatutorial\example> javac HelloWorld.java 'javac' is not recognized as an internal or external
Java while coding - Java Beginners
Java while coding  Java loop and function coding question? How can I write an application that accepts a person's weight and displays the number...; } } while (boolexit); } } Thanks
Dll issue while launching the application
Dll issue while launching the application  I am using one dll in my application for including the functionality provided by that dll . This dll i am... is if the user has not installed the msi , then while launching the application
Do While Loop in Java
Do while loop in Java There are three loops most commonly used in Java e.g. While loop, Do….While loop, and For loop. These loops are used.... Do while loop is java is slightly different with While loop as in While loop
HOW TO I CHANGE THE SWITCH TO IF ELSE OR DO WHILE OR WHILE DO FOR THIS CODING
HOW TO I CHANGE THE SWITCH TO IF ELSE OR DO WHILE OR WHILE DO..."); System.out.println("| q. Quit"); question = console.next().charAt(0... 'l': CheckEmptyList(); case 'q': Quit(); case 'Q
HOW TO I CHANGE THE SWITCH TO IF ELSE OR DO WHILE OR WHILE DO FOR THIS CODING
HOW TO I CHANGE THE SWITCH TO IF ELSE OR DO WHILE OR WHILE DO..."); System.out.println("| q. Quit"); question = console.next().charAt(0... 'l': CheckEmptyList(); case 'q': Quit(); case 'Q
HOW TO I CHANGE THE SWITCH TO IF ELSE OR DO WHILE OR WHILE DO FOR THIS CODING
HOW TO I CHANGE THE SWITCH TO IF ELSE OR DO WHILE OR WHILE DO..."); System.out.println("| q. Quit"); question = console.next().charAt(0... 'l': CheckEmptyList(); case 'q': Quit(); case 'Q
HOW TO I CHANGE THE SWITCH TO IF ELSE OR DO WHILE OR WHILE DO FOR THIS CODING
HOW TO I CHANGE THE SWITCH TO IF ELSE OR DO WHILE OR WHILE DO..."); System.out.println("| q. Quit"); question = console.next().charAt(0... 'l': CheckEmptyList(); case 'q': Quit(); case 'Q
problem while reading .csv file
problem while reading .csv file  I have a problem here..... i am reading a .csv extention file which has some value....but the problem is der is an amount column which contains , in between (eg) 3,899.00 which inturns creates
PHP While Loop
While Control Structure: While is the simplest form of loop. While loop checks..., and become infinite loop. While loop is also known as pre-test loop. Basic format of while loop is as follows: ADS_TO_REPLACE_1 while(condition
do-while Loop in Java
do-while Loop in Java      ... and processes once at least. For that you have to use the do while loop in  after that check the condition then we use the do-while loop statement. do-while loop
do while loop
do while loop       In java a do while loop is a control flow statement that allows a certain code... with a condition associated with the while keyword. The code inside the do construct
PHP Do While Loop
Do-While Control Structure: Do-While loop is another type of loop which runs... within. We generally use Do-While loop  when the iteration must run at least once despite of the validity of the variable. In Do-While loop we need

Ads