使用 saxon 将 XdmValue 作为 XmlType 存储在数据库中的更好方法。

Better way to store XdmValue in the database as XmlType using saxon.

我正在使用 Saxon 9API 执行 XQuery。 XQuery 的结果返回为 net.sf.saxon。s9api.XdmValue.I 正在从此 XdmValue 构造 DOM 文档对象。我正在粘贴下面的代码。

    Processor saxon = new Processor(false);
    saxon.registerExtensionFunction(new MyExtension());

    XQueryCompiler compiler = saxon.newXQueryCompiler();
    XQueryExecutable exec = compiler.compile(new File("input/studentXQuery.xq"));
    XQueryEvaluator query = exec.load();


    String students = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><student_list><student><name>George Washington</name><major>Politics</major><phone>312-123-4567</phone><email>gw@example.edu</email></student><student><name>Janet Jones</name><major>Undeclared</major><phone>311-122-2233</phone><email>janetj@example.edu</email></student><student><name>Joe Taylor</name><major>Engineering</major><phone>211-111-2333</phone><email>joe@example.edu</email></student></student_list>";
    javax.xml.parsers.DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    InputSource is = new InputSource();
    is.setCharacterStream(new StringReader(students));
    Document doc1 = db.parse(is);


    DocumentBuilder builder = saxon.newDocumentBuilder();
    Source src = new DOMSource(doc1);
    XdmNode doc = builder.build(src);
    query.setExternalVariable(new QName("student_list"), doc);

    XdmValue result = query.evaluate();

    System.out.println("Result is -------- "+result.toString());
    InputSource is1 = new InputSource();
    is1.setCharacterStream(new StringReader(result.toString()));
    Document resultDoc = db.parse(is1);
    System.out.println("Result doc is "+resultDoc);

我的问题是在 Oracle DB 中将此输出存储为 XmlType 的更好方法是什么。是否需要 DOM 文档构造来避免处理字符串以保存 xml 值?或者是在 String 本身之上构造 XmlType 的好方法。非常感谢任何帮助。

使用 DOM 作为中间形式似乎很笨拙。我怀疑它就像 easy/fast 序列化 Saxon 结果并从字符串中重新解析它一样 - 但我不知道 Oracle 提供了哪些选项。