Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

org.xml.sax.SAXParseException: Document root element is missing.
Hi,
I get this error when i try to parse my XML file. The code is pasted
below and the XML file too is pasted. I don't understand why I am
getting this error even when the xml input seems correct.

Stack Trace :
org.xml.sax.SAXParseException: Document root element is missing.
at org.apache.crimson.parser.Parser2.fatal(Unknown Source)
at org.apache.crimson.parser.Parser2.fatal(Unknown Source)
at org.apache.crimson.parser.Parser2.parseInternal(Unknown Source)
at org.apache.crimson.parser.Parser2.parse(Unknown Source)
at org.apache.crimson.parser.XMLReaderImpl.parse(Unknown Source)
at org.apache.crimson.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
at tsafe.test.SimpleTest.getExpectetValue(SimpleTest.java:139)
at tsafe.test.SimpleTest.blunderTest(SimpleTest.java:89)
at tsafe.engine.TsafeEngine.start(TsafeEngine.java:158)
at tsafe.client.TsafeClient.actionPerformed(TsafeClient.java:197)
at javax.swing.Timer.fireActionPerformed(Unknown Source)
at javax.swing.Timer$DoPostEvent.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at tsafe.main.gui.utils.WaitCursorEventQueue.dispatchEvent(WaitCursorEventQu
eue.java:61)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown
Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown
Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

Code :

private static String getExpectetValue(
String planeIdentifier,
String testCase)
throws IOException {
if (!new File(inputFile + ".xml").exists()) {
throw new IOException("Testinput file does not exist");
}

DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = null;

try {
//load input data
builder = fact.newDocumentBuilder();
Document doc = builder.parse(new File(inputFile + ".xml"));

//prerequisite is that the identifier in the file is unique

//Get all planes
NodeList elementListPlanes = doc.getElementsByTagName("plane");

//find the searched one
Element elementPlane =
getPlaneFromList(planeIdentifier, elementListPlanes);

//searched plane doesn't exist
if (elementPlane == null)
return null;

//get the test expected value
Element elementBlunder =
(Element) elementPlane.getElementsByTagName(testCase).item(0);

//if no testcase is in the input file
if (elementBlunder == null)
return null;

String s =
elementBlunder
.getElementsByTagName("expected")
.item(0)
.getChildNodes()
.item(0)
.getNodeValue();

return s;

} catch (ParserConfigurationException e) {
e.printStackTrace();
return null;
} catch (SAXException e) {
e.printStackTrace();
return null;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}


Input file :
<?xml version="1.0" encoding="UTF-8" ?>
<planes>
<plane id="QW">
<TST001>
<expected>YES</expected>
</TST001>
</plane>
</planes>

Please suggest.

Thanks in advance.

Regards,
Kunal

Report this thread to moderator Post Follow-up to this message
Old Post
Kunal
10-24-04 08:56 AM


Re: org.xml.sax.SAXParseException: Document root element is missing.
I'm sure error is not in this code.
Probably it's in method
getPlaneFromList(planeIdentifier, elementListPlanes);
which you didn't post here.

What you was pasted runs fine.

Alex Kizub.

Kunal wrote:

> Hi,
> I get this error when i try to parse my XML file. The code is pasted
> below and the XML file too is pasted. I don't understand why I am
> getting this error even when the xml input seems correct.
>
> Stack Trace :
> org.xml.sax.SAXParseException: Document root element is missing.
>         at org.apache.crimson.parser.Parser2.fatal(Unknown Source)
>         at org.apache.crimson.parser.Parser2.fatal(Unknown Source)
>         at org.apache.crimson.parser.Parser2.parseInternal(Unknown Source)
>         at org.apache.crimson.parser.Parser2.parse(Unknown Source)
>         at org.apache.crimson.parser.XMLReaderImpl.parse(Unknown Source)
>         at org.apache.crimson.jaxp.DocumentBuilderImpl.parse(Unknown Sourc
e)
>         at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
>         at tsafe.test.SimpleTest.getExpectetValue(SimpleTest.java:139)
>         at tsafe.test.SimpleTest.blunderTest(SimpleTest.java:89)
>         at tsafe.engine.TsafeEngine.start(TsafeEngine.java:158)
>         at tsafe.client.TsafeClient.actionPerformed(TsafeClient.java:197)
>         at javax.swing.Timer.fireActionPerformed(Unknown Source)
>         at javax.swing.Timer$DoPostEvent.run(Unknown Source)
>         at java.awt.event.InvocationEvent.dispatch(Unknown Source)
>         at java.awt.EventQueue.dispatchEvent(Unknown Source)
>         at tsafe.main.gui.utils.WaitCursorEventQueue.dispatchEvent(WaitCur
sorEventQueue.java:61)
>         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown
> Source)
>         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown
> Source)
>         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
>         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
>         at java.awt.EventDispatchThread.run(Unknown Source)
>
> Code :
>
>         private static String getExpectetValue(
>                 String planeIdentifier,
>                 String testCase)
>                 throws IOException {
>                 if (!new File(inputFile + ".xml").exists()) {
>                         throw new IOException("Testinput file does not exi
st");
>                 }
>
>                 DocumentBuilderFactory fact = DocumentBuilderFactory.newIn
stance();
>                 DocumentBuilder builder = null;
>
>                 try {
>                         //load input data
>                         builder = fact.newDocumentBuilder();
>                         Document doc = builder.parse(new File(inputFile + 
".xml"));
>
>                         //prerequisite is that the identifier in the file 
is unique
>
>                         //Get all planes
>                         NodeList elementListPlanes = doc.getElementsByTagN
ame("plane");
>
>                         //find the searched one
>                         Element elementPlane =
>                                 getPlaneFromList(planeIdentifier, elementL
istPlanes);
>
>                         //searched plane doesn't exist
>                         if (elementPlane == null)
>                                 return null;
>
>                         //get the test expected value
>                         Element elementBlunder =
>                                 (Element) elementPlane.getElementsByTagNam
e(testCase).item(0);
>
>                         //if no testcase is in the input file
>                         if (elementBlunder == null)
>                                 return null;
>
>                         String s =
>                                 elementBlunder
>                                         .getElementsByTagName("expected")
>                                         .item(0)
>                                         .getChildNodes()
>                                         .item(0)
>                                         .getNodeValue();
>
>                         return s;
>
>                 } catch (ParserConfigurationException e) {
>                         e.printStackTrace();
>                         return null;
>                 } catch (SAXException e) {
>                         e.printStackTrace();
>                         return null;
>                 } catch (IOException e) {
>                         e.printStackTrace();
>                         return null;
>                 }
>         }
>
> Input file :
> <?xml version="1.0" encoding="UTF-8" ?>
> <planes>
>         <plane id="QW">
>                  <TST001>
>                         <expected>YES</expected>
>                 </TST001>
>         </plane>
> </planes>
>
> Please suggest.
>
> Thanks in advance.
>
> Regards,
> Kunal


Report this thread to moderator Post Follow-up to this message
Old Post
Alex Kizub
10-24-04 08:56 AM


Re: org.xml.sax.SAXParseException: Document root element is missing.
Hi Alex,
The error was due to the wrongpath from this file was getting read.
The problem i mentioned does not occur now, but you are right it is in
the method, which I think I can overcome.
Thanks,

kunal
Alex Kizub <akizub@yahoo.com> wrote in message news:<417B2B98.443FBF2@yahoo.com>...[color=d
arkred]
> I'm sure error is not in this code.
> Probably it's in method
> getPlaneFromList(planeIdentifier, elementListPlanes);
> which you didn't post here.
>
> What you was pasted runs fine.
>
> Alex Kizub.
>
> Kunal wrote:
> 

Report this thread to moderator Post Follow-up to this message
Old Post
Kunal
10-24-04 08:57 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Java Help archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:41 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.