Solved

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

Posted on 2007-03-23
7
996 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
ID: 18783371
You can only use the outputtter once probably. Try just


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

Author Comment

by:fortneci
ID: 18783440
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
ID: 18783464
Please post your current code
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:fortneci
ID: 18783471
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
ID: 18783481
You're not writing anything to the output stream. Try

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

Author Comment

by:fortneci
ID: 18783508
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
ID: 18784671
:-) 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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
tomcat startup error 5 104
jboss 7.1 start up error 1 39
Java class and jar 3 24
XML and version of MS XML Dom Document versions 5 13
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…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

838 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