gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 11:31:09 25 4
gpt4 key购买 nike

我正在使用 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);

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

最佳答案

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

关于java - 使用 saxon 将 XdmValue 作为 XmlType 存储在数据库中的更好方法。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30366444/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com