Solved

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

Posted on 2007-03-23
7
997 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
The viewer will learn how to implement Singleton Design Pattern in Java.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

740 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