Bug 6064 - Can not parse XML
Summary: Can not parse XML
Status: CLOSED FIXED
Alias: None
Product: Taglibs
Classification: Unclassified
Component: Standard Taglib (show other bugs)
Version: 1.0
Hardware: Sun Solaris
: P3 major (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-01-28 12:50 UTC by peter lin
Modified: 2004-11-16 19:05 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description peter lin 2002-01-28 12:50:42 UTC
when I try to load from a static or dynamic source, I get an entity error.

javax.servlet.ServletException: org.xml.sax.SAXParseException: XML declaration 
may only begin entities.
        at org.apache.jasper.runtime.PageContextImpl.handlePageException(Unknown 
Source)
        at org.apache.jsp.xtag$jsp._jspService(xtag$jsp.java:290)
        at org.apache.jasper.runtime.HttpJspBase.service(Unknown Source)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at 
org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(Unknown Source)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(Unknown Source)
        at org.apache.jasper.servlet.JspServlet.service(Unknown Source)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Unknown Source)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(Unknown 
Source)
        at org.apache.catalina.core.StandardWrapperValve.invoke(Unknown Source)
        at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
        at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
        at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
        at org.apache.catalina.core.StandardContextValve.invoke(Unknown Source)
        at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
        at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
        at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
        at org.apache.catalina.core.StandardContext.invoke(Unknown Source)
        at org.apache.catalina.core.StandardHostValve.invoke(Unknown Source)
        at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
        at org.apache.catalina.valves.AccessLogValve.invoke(Unknown Source)
        at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
        at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
        at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
        at org.apache.catalina.core.StandardEngineValve.invoke(Unknown Source)
        at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
        at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
        at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
        at org.apache.catalina.connector.http.HttpProcessor.process(Unknown 
Source)
        at org.apache.catalina.connector.http.HttpProcessor.run(Unknown Source)
        at java.lang.Thread.run(Thread.java:484)


<%@ taglib prefix="jc" uri="http://java.sun.com/jstl/ea/core" %>
<%@ taglib prefix="jx" uri="http://java.sun.com/jstl/ea/xml" %>
<html>
<head>
  <title>my Listings</title>
</head>
<body bgcolor="#FFFFFF">

<a href="xtag.txt">Source</a><p>
<jc:set var="xmlurl">
http://localhost:8080/mylisting/sample.xml?
</jc:set>

<jx:parse var="dom">
<jc:import url="$xmlurl"/>
</jx:parse>

<h3>Listings</h3>

<table border=1 width="100%">
<jx:forEach var="cat" select="$dom//cat">
<tr>
   <td>
   	<a href="<jx:expr select="$cat/url"/>"><jx:expr select="$cat/name"/></a>
   </td>
   <td>
   	<jx:expr select="$cat/lNum"/>
   </td>
</tr>
</jx:forEach>
</table>

</body>
</html>


Example XML:

<?xml version="1.0"?>
<spPage>
<catPage totalCats="11" query_stype="S" query_category="" query_name="pet" 
query_street="" query_city="worcester" query_state="MA" query_zip="" 
query_miles="" pageStartsAt="1" pageSize="11" totalListings="26">
<cat cid="0752AE12400" level="0" rank="428">
      <name>Dog &#38; Cat Grooming &#38; Boarding</name>
      <url 
name="listings_page">xtag.jsp?CID=0752AE12400&#38;T=worcester&#38;N=pet&#38;PG=L
&#38;STYPE=S&#38;R=N&#38;S=MA&#38;MC=1&#38;PI=1</url>
      <lNum>1</lNum>
    </cat>
<cat cid="0752AF12426" level="0" rank="683">
      <name>Dog &#38; Cat Kennels</name>
      <url 
name="listings_page">xtag.jsp?CID=0752AF12426&#38;T=worcester&#38;N=pet&#38;PG=L
&#38;STYPE=S&#38;R=N&#38;S=MA&#38;MC=1&#38;PI=1</url>
      <lNum>1</lNum>
    </cat>
<cat cid="0752BC1243A" level="0" rank="1205">
      <name>Dog &#38; Cat Pet Sitting Services</name>
      <url 
name="listings_page">xtag.jsp?CID=0752BC1243A&#38;T=worcester&#38;N=pet&#38;PG=L
&#38;STYPE=S&#38;R=N&#38;S=MA&#38;MC=1&#38;PI=1</url>
      <lNum>1</lNum>
    </cat>
<cat cid="0752BA29702" level="0" rank="856">
      <name>Pet Care Services</name>
      <url 
name="listings_page">xtag.jsp?CID=0752BA29702&#38;T=worcester&#38;N=pet&#38;PG=L
&#38;STYPE=S&#38;R=N&#38;S=MA&#38;MC=1&#38;PI=1</url>
      <lNum>4</lNum>
    </cat>
<cat cid="5999CJ29748" level="0" rank="1516">
      <name>Pet Clothing &#38; Accessories</name>
      <url 
name="listings_page">xtag.jsp?CID=5999CJ29748&#38;T=worcester&#38;N=pet&#38;PG=L
&#38;STYPE=S&#38;R=N&#38;S=MA&#38;MC=1&#38;PI=1</url>
      <lNum>2</lNum>
    </cat>
<cat cid="5999CJ297DE" level="0" rank="380">
      <name>Pet Foods Equipment &#38; Supplies</name>
      <url 
name="listings_page">xtag.jsp?CID=5999CJ297DE&#38;T=worcester&#38;N=pet&#38;PG=L
&#38;STYPE=S&#38;R=N&#38;S=MA&#38;MC=1&#38;PI=1</url>
      <lNum>2</lNum>
    </cat>
<otherLinks></otherLinks>
</catPage>
</spPage>
Comment 1 peter lin 2002-01-29 16:03:01 UTC
I have more information on this bug. It appears to be caused by  
org.apache.taglibs.standard.tag.el.xml.ParseSupport and not 
org.apache.taglibs.xtags.xtags.xpath.ParseTag. The Xtags version loads static 
files with "<?xml version="1.0"?>" without any problems, but ParseSupport 
definitely has a problem.
Comment 2 peter lin 2002-02-08 17:29:01 UTC
I did some additional testing with javax.xml.parser.DocumentBuilder and it looks 
like it is specific to parse(string) and parse(inputstream). when I use 
parse(file), it works fine. One possible fix could be to check the first line of 
the source and parse it out.
Comment 3 peter lin 2002-02-08 17:52:54 UTC
spoke too soon, user error on my part. fixed my xml file and documentbuilder 
works fine for all three parse() methods.
Comment 4 peter lin 2002-02-11 19:05:53 UTC
I found the bug in line 146 of 
org.apache.taglibs.standard.tag.common.xml.ParseSupport.

For some reason, bodyContent.getString pads the beginning of the document with 
an extra line. I verified the ImportTag gets the content correctly, so it 
happens when in between the time import gets the content and parse tag gets it 
from the body content. The fix was simple. I add .trim() to the line and it 
works correctly.


	// if we haven't gotten a source, use the body (which may be empty)
	Object source = this.source;
	if (source == null)
	    source = bodyContent.getString().trim();