Solved

XML Parsing Error: no element found - Using JDOM w/ Java Servlet

Posted on 2007-03-23
7
990 Views
Last Modified: 2012-06-27
I am getting the following error when I hit this servlet
ERROR:
XML Parsing Error: no element found
Location: http://url/LeagueStandings
Line Number 1, Column 1:

SERVLET CODE:
           RStoXML rsxml = new RStoXML(results, "ResultSet", "Result");
            //create the XML from recordset
            Document jDOMDoc = rsxml.build();            
            results.close();
            XMLOutputter outputter = new XMLOutputter() ;
            StringWriter writer = new StringWriter() ;
            outputter.output( jDOMDoc, writer );
            writer.close() ;
            //respond with output stream
            rep.setContentType("text/xml");
            rep.getOutputStream();
 logger.debug(outputter.outputString(jDOMDoc));

The XML returned in the debug message is below.
XML:
<?xml version="1.0" encoding="UTF-8"?>
<ResultSet>
    <Result>
         <ROUNDS>3</ROUNDS>
         <USERNAME>testuser</USERNAME>
         <BIRDIES>2</BIRDIES>
         <PARS>13</PARS>
         <BOGIES>28</BOGIES>
         <DOUBLES>11</DOUBLES>
         <GH>10</GH>
        <FH>10</FH>
        <PUTTS>108</PUTTS>
        <SCORES>264</SCORES>
    </Result>
</ResultSet>

0
Comment
Question by:fortneci
  • 4
  • 3
7 Comments
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
You can only use the outputtter once probably. Try just


rep.setContentType("text/xml");
outputter.output( jDOMDoc, rep.getWriter() );
0
 

Author Comment

by:fortneci
Comment Utility
I put the  logger.debug(outputter.outputString(jDOMDoc)); in there after I experienced the error to check the XML, but I just took it out just in case and I am still getting the error.
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
Please post your current code
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:fortneci
Comment Utility
The section of the Servlet:

            RStoXML rsxml = new RStoXML(results, "ResultSet", "Result");
            //create the XML from recordset
            Document jDOMDoc = rsxml.build();            
            results.close();
            XMLOutputter outputter = new XMLOutputter() ;
            StringWriter writer = new StringWriter() ;
            outputter.output( jDOMDoc, writer );
            writer.close() ;
            //respond with output stream
            rep.setContentType("text/xml");
            rep.getOutputStream();
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
Comment Utility
You're not writing anything to the output stream. Try

rep.getWriter().println(writer.toString());
0
 

Author Comment

by:fortneci
Comment Utility
Thanks, that got rid of the error. Below is the final snippet of code.

            RStoXML rsxml = new RStoXML(results, "ResultSet", "Result");
            //create the XML from recordset
            Document jDOMDoc = rsxml.build();            
            results.close();
            XMLOutputter outputter = new XMLOutputter() ;
            StringWriter writer = new StringWriter() ;
            outputter.output( jDOMDoc, writer );
            writer.close() ;
            //respond with output stream
            rep.setContentType("text/xml");
            rep.getWriter().println(writer.toString());
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
:-) If you don't need 'writer' again you should be able to do

RStoXML rsxml = new RStoXML(results, "ResultSet", "Result");
//create the XML from recordset
Document jDOMDoc = rsxml.build();            
results.close();
XMLOutputter outputter = new XMLOutputter() ;
rep.setContentType("text/xml");
outputter.output( jDOMDoc, rep.getWriter() );
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
for i loop in grovy 1 32
groovy example issue 10 65
Starting to learn JAVA, 7 46
API Soap Calls 4 55
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
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:

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now