You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by "Kransen, J." <j....@srn.minjus.nl> on 2004/07/01 11:15:43 UTC

Parsing XML file retrieved through HTTP

Hello, 

I have a .jsp that outputs a XML file. I have another .jsp in which I want
to parse the XML file using an XSL file. So in the latter .jsp I want to do
something like this:

<textarea><%

String xslFile = getServletContext().getRealPath("/xml/risc2cvs.xsl");

TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer
transformer = tFactory.newTransformer(new StreamSource(xslFile));

// write the content of the parsed XML file 
transformer.transform(new
StreamSource("http://localhost/risc/readonly.jsp"), new StreamResult(out));

%></textarea>

However, when I do this, I get the following error message:

The element type "base" must be terminated by the matching end-tag "".

With this stack trace:
javax.xml.transform.TransformerException: The element type "base" must be
terminated by the matching end-tag "".
	at
org.apache.xalan.transformer.TransformerImpl.fatalError(TransformerImpl.java
:744)
	at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:
720)
	at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:
1192)
	at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:
1170)
	at
org.apache.jsp.cvs_005fuittreksel_jsp._jspService(cvs_005fuittreksel_jsp.jav
a:109)
...


When instead I try to parse a local XML file, there are no problems: 
String xmlFile = getServletContext().getRealPath("/xml/temp.xml");
transformer.transform(new StreamSource(xmlFile), new StreamResult(out));

But then, when I try to parse the very same file as accessed through HTTP, I
get the very same error: 
transformer.transform(new
StreamSource("http://localhost/risc/xml/temp.xml"), new StreamResult(out));

I was thinking that maybe the HTTP headers aren't stripped before the
parsing. Does anybody know what to do here?

Thanks in advance!

Jeroen


RE: Parsing XML file retrieved through HTTP

Posted by Russell Simpkins <ru...@hotmail.com>.
Jeroen,

Did you look at the xml file through a brower?  Maybe there is something
there you aren't seeing.  I have done the exact same thing, opening an
http page as a streamsource, using php as the source.  Every error I saw
came in malformed xml.  Which is what it sounds like you have.

Russ

-----Original Message-----
From: Kransen, J. [mailto:j.kransen@srn.minjus.nl] 
Sent: Thursday, July 01, 2004 5:16 AM
To: 'xalan-j-users@xml.apache.org'
Subject: Parsing XML file retrieved through HTTP

Hello, 

I have a .jsp that outputs a XML file. I have another .jsp in which I
want
to parse the XML file using an XSL file. So in the latter .jsp I want to
do
something like this:

<textarea><%

String xslFile = getServletContext().getRealPath("/xml/risc2cvs.xsl");

TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer
transformer = tFactory.newTransformer(new StreamSource(xslFile));

// write the content of the parsed XML file 
transformer.transform(new
StreamSource("http://localhost/risc/readonly.jsp"), new
StreamResult(out));

%></textarea>

However, when I do this, I get the following error message:

The element type "base" must be terminated by the matching end-tag "".

With this stack trace:
javax.xml.transform.TransformerException: The element type "base" must
be
terminated by the matching end-tag "".
	at
org.apache.xalan.transformer.TransformerImpl.fatalError(TransformerImpl.
java
:744)
	at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.j
ava:
720)
	at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.j
ava:
1192)
	at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.j
ava:
1170)
	at
org.apache.jsp.cvs_005fuittreksel_jsp._jspService(cvs_005fuittreksel_jsp
jav
a:109)
..


When instead I try to parse a local XML file, there are no problems: 
String xmlFile = getServletContext().getRealPath("/xml/temp.xml");
transformer.transform(new StreamSource(xmlFile), new StreamResult(out));

But then, when I try to parse the very same file as accessed through
HTTP, I
get the very same error: 
transformer.transform(new
StreamSource("http://localhost/risc/xml/temp.xml"), new
StreamResult(out));

I was thinking that maybe the HTTP headers aren't stripped before the
parsing. Does anybody know what to do here?

Thanks in advance!

Jeroen