Skip to content

Instantly share code, notes, and snippets.

@dustinschultz
Created June 7, 2013 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dustinschultz/5731418 to your computer and use it in GitHub Desktop.
Save dustinschultz/5731418 to your computer and use it in GitHub Desktop.
" throws SAXParseException, other special entities are parsed correctly.
/**
* Copyright (C) [2013] [The FURTHeR Project]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package edu.utah.further.mdr.impl.service.uml;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.xquery.XQConnection;
import javax.xml.xquery.XQDataSource;
import javax.xml.xquery.XQException;
import javax.xml.xquery.XQPreparedExpression;
import javax.xml.xquery.XQResultSequence;
import net.xqj.basex.BaseXXQDataSource;
import org.basex.BaseXServer;
/**
* ...
* <p>
* -----------------------------------------------------------------------------------<br>
* (c) 2008-2012 FURTHeR Project, Health Sciences IT, University of Utah<br>
* Contact: {@code <further@utah.edu>}<br>
* Biomedical Informatics, 26 South 2000 East<br>
* Room 5775 HSEB, Salt Lake City, UT 84112<br>
* Day Phone: 1-801-581-4080<br>
* -----------------------------------------------------------------------------------
*
* @author N. Dustin Schultz {@code <dustin.schultz@utah.edu>}
* @version Jun 7, 2013
*/
public class BugSaxParse
{
public static void main(final String[] args) throws IOException, XMLStreamException,
XQException
{
final BaseXServer server = new BaseXServer();
final Thread t = new Thread(server);
t.start();
final String problemXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><element someAttribute=\"&quot;Escaped but quoted string&quot;\"></element>";
// &amp; works OK: "<?xml version=\"1.0\" encoding=\"UTF-8\"?><element someAttribute=\"&amp;Escaped but quoted string&amp;\"></element>";
// &gt; &lt; work OK: "<?xml version=\"1.0\" encoding=\"UTF-8\"?><element someAttribute=\"&lt;Escaped but quoted string&gt;\"></element>";
// &quot; fails
System.out.println("Try XML: " + problemXml);
XQConnection conn = null;
try
{
final XQDataSource xqs = new BaseXXQDataSource();
xqs.setProperty("serverName", "localhost");
xqs.setProperty("port", "1984");
xqs.setProperty("user", "admin");
xqs.setProperty("password", "admin");
conn = xqs.getConnection();
final XQPreparedExpression xqpe = conn
.prepareExpression("declare variable $x as document-node() external; $x");
final XMLInputFactory factory = XMLInputFactory.newInstance();
final XMLStreamReader xmlStreamReader = factory
.createXMLStreamReader(new ByteArrayInputStream(problemXml.getBytes()));
xqpe.bindDocument(new QName("x"), xmlStreamReader, null);
final XQResultSequence rs = xqpe.executeQuery();
while (rs.next())
System.out.println(rs.getItemAsString(null));
}
finally
{
if (conn != null)
{
conn.close();
}
server.stop();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment