在尝试使用Xquery解析xml时,出现以下异常, javax.xml.xquery.XQException:不得以大小写的任何组合将处理指令命名为“ xml”。第1行第1行在{... rsion =“ 1.0” encoding =“ UTF-8 ...}附近的语法错误 XPST0003:不得以高位和高位的任何组合将处理指令命名为“ xml” 小写。下面给出的是XML文件。有人可以建议在这里做什么。
<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book category="COOKING">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="CHILDREN">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
</bookstore>
答案 0 :(得分:3)
我认为您在期望XQuery文件时已经向XQuery处理器提供了XML文件。 XML中的大多数内容在XQuery中也有效,但是XML声明是一个例外。 (除了不允许使用名为“ xml”的处理指令外,这将被视为处理指令。)
检查如何调用XQuery处理器。您正在提供一个期望查询的XML数据文件。
答案 1 :(得分:0)
尝试一下,
XQueryMain.java(java)
The form:
<form action="*/myobject/mymethod/uploadFile" method="post" enctype="multipart/form-data">
<label for="exampleInputFile">File input</label>
<input type="file" id="file" name="file">
<p class="help-block">Upload a file to link.</p>
<input type="text" name="myId" id="myId" value="{{theId}}" style="display:none;">
<button type="submit" name="submit" value="Upload File" class="btn btn-primary">
<span class="glyphicon glyphicon-upload"></span> Upload File
</button>
</form>
My PHP method
public static uploadFile()
{
there are calls to various methods that do the actual upload. These methods can return
errors if something caused the upload to not work properly.
If I want to return an error to display to the user do I:
return "File did not upload";
or
return 'error';
If no errors and all went well, I would like a message displayed to say it was successful.
}
condition.xqy(XQuery)
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
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 com.saxonica.xqj.SaxonXQDataSource;
public class XQueryMain {
public static void main(String[] args){
try {
InputStream inputStream = new FileInputStream(new File("condition.xqy"));
XQDataSource dataSource = new SaxonXQDataSource();
XQConnection connection = dataSource.getConnection();
XQPreparedExpression preparedExpression = connection.prepareExpression(inputStream);
XQResultSequence resultSequence = preparedExpression.executeQuery();
while (resultSequence.next()) {
System.out.println(resultSequence.getItemAsString(null));
}
}
catch (FileNotFoundException | XQException e) {
e.printStackTrace();
}
}
}
bookstore.xml(XML)
for $x in doc("bookstore.xml")/bookstore/book
where $x/price=30
return $x/title
将以下jar文件(SaxonHE9-9-0-2J)添加到类路径