Created
June 7, 2013 18:40
-
-
Save dustinschultz/5731418 to your computer and use it in GitHub Desktop.
" throws SAXParseException, other special entities are parsed correctly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 <[email protected]>}<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 <[email protected]>} | |
* @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=\""Escaped but quoted string"\"></element>"; | |
// & works OK: "<?xml version=\"1.0\" encoding=\"UTF-8\"?><element someAttribute=\"&Escaped but quoted string&\"></element>"; | |
// > < work OK: "<?xml version=\"1.0\" encoding=\"UTF-8\"?><element someAttribute=\"<Escaped but quoted string>\"></element>"; | |
// " 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