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 & Cat Grooming & Boarding</name> <url name="listings_page">xtag.jsp?CID=0752AE12400&T=worcester&N=pet&PG=L &STYPE=S&R=N&S=MA&MC=1&PI=1</url> <lNum>1</lNum> </cat> <cat cid="0752AF12426" level="0" rank="683"> <name>Dog & Cat Kennels</name> <url name="listings_page">xtag.jsp?CID=0752AF12426&T=worcester&N=pet&PG=L &STYPE=S&R=N&S=MA&MC=1&PI=1</url> <lNum>1</lNum> </cat> <cat cid="0752BC1243A" level="0" rank="1205"> <name>Dog & Cat Pet Sitting Services</name> <url name="listings_page">xtag.jsp?CID=0752BC1243A&T=worcester&N=pet&PG=L &STYPE=S&R=N&S=MA&MC=1&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&T=worcester&N=pet&PG=L &STYPE=S&R=N&S=MA&MC=1&PI=1</url> <lNum>4</lNum> </cat> <cat cid="5999CJ29748" level="0" rank="1516"> <name>Pet Clothing & Accessories</name> <url name="listings_page">xtag.jsp?CID=5999CJ29748&T=worcester&N=pet&PG=L &STYPE=S&R=N&S=MA&MC=1&PI=1</url> <lNum>2</lNum> </cat> <cat cid="5999CJ297DE" level="0" rank="380"> <name>Pet Foods Equipment & Supplies</name> <url name="listings_page">xtag.jsp?CID=5999CJ297DE&T=worcester&N=pet&PG=L &STYPE=S&R=N&S=MA&MC=1&PI=1</url> <lNum>2</lNum> </cat> <otherLinks></otherLinks> </catPage> </spPage>
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.
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.
spoke too soon, user error on my part. fixed my xml file and documentbuilder works fine for all three parse() methods.
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();