Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

xml parse works via command line - not in servlet

1 view
Skip to first unread message

Dan Dugal

unread,
Apr 30, 2000, 3:00:00 AM4/30/00
to
This one has me stumped. I am using a servlet to display xml based
information in html. The process is to get
a Runtime and create the InputSource from the process.getInputStream
method. Currently I just have a ksh
script 'cat' an xml file (included below). Eventually, I will have the
script return dynamic xml wrapped data.

Everything works fine from the command line (via main methods or driver
programs) but I get a
SAXParseException (stack trace below) when run in "servlet mode" telling
me that the document root is
missing. Any help would be appreciated!!

I am using the jaxp parser, Apache 1.3.11/JServ on an HP/UX 11.00
machine. The code looks like this:

InputSource is;
XmlDocument doc;
Element element;

try{
is = new InputSource(process.getInputStream()); // <-- this works
fine
xmlDoc = XmlDocument.createXmlDocument(is, false); // <-- throws
exception in servlet
element = xmlDoc.getDocumentElement(); // <-- I never get
here

NodeList dealerNodeList = element.getElementsByTagName("Dealer");
// cycle throug all the top level (dealer) nodes and do 'stuff'
...
...
}
catch(SAXParseException spe){
spe.printStackTrace();
}


The XML file:
<?xml version="1.0" ?>
<DealerList>
<Dealer>
<Name>ACME supply</Name>
<Address>123 Main Street</Address>
<City>Chicago</City>
<State>IL</State>
<Zip>12345</Zip>
</Dealer>
<Dealer>
<Name>Roadrunner Warehouse</Name>
<Address>456 1st Ave</Address>
<City>Denver</City>
<State>CO</State>
<Zip>67890</Zip>
</Dealer>
</DealerList>


Java Stack Trace:
org.xml.sax.SAXParseException: Document root element is missing.
at com.sun.xml.parser.Parser.fatal(Parser.java:2817)
at com.sun.xml.parser.Parser.fatal(Parser.java:2805)
at com.sun.xml.parser.Parser.parseInternal(Parser.java:493)
at com.sun.xml.parser.Parser.parse(Parser.java:284)

atcom.sun.xml.tree.XmlDocument.createXmlDocument(XmlDocument.java:226)
at JDealerLookup.initFromXMLdlr(JDealerLookup.java:123)
at JDealerLookup.<init>(JDealerLookup.java:41)
at MarketLocator.serveFrom_XMLdlr(MarketLocator.java:351)
at MarketLocator.service(MarketLocator.java:172)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:588)

atorg.apache.jserv.JServConnection.processRequest(JServConnection.java:314)

at
org.apache.jserv.JServConnection.run(JServConnection.java:188)
at java.lang.Thread.run(Thread.java:479)

0 new messages