【问题标题】:Better way to store XdmValue in the database as XmlType using saxon.使用 saxon 将 XdmValue 作为 XmlType 存储在数据库中的更好方法。
【发布时间】:2015-05-21 06:47:09
【问题描述】:

我正在使用 Saxon 9API 执行 XQuery。 XQuery 的结果以 net.sf.saxon.s9api.XdmValue 的形式返回。我正在从这个 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);

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

【问题讨论】:

    标签: java oracle saxon xmltype


    【解决方案1】:

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

    【讨论】:

    • 与检索 DOM 对象并使用它来构建 Oracle XMLType 相比,将 XDMValue 转换为字符串并将其解析为 Oracle XMLType 将是一项昂贵的操作(性能)。如果 DOM 与 String 相对应,我假设 Oracle 和 Saxon 都会使用优化。有没有办法在上面的例子中提取 DOM。请注意,这两种方法的性能都将被评估..
    • 我很想看看你的测量结果。通常,DOM 很慢,几乎其他任何东西通常都是可取的。
    猜你喜欢
    • 2014-03-31
    • 2015-03-01
    • 2013-12-28
    • 2011-03-17
    • 1970-01-01
    • 2021-07-30
    • 1970-01-01
    • 2018-04-11
    • 2023-03-03
    相关资源
    最近更新 更多