[英]How do you update XML content in Jackrabbit using an XPath query?
I am using Jackrabbit 2.4.0 and I am having trouble updating XML which has been imported using: 我正在使用Jackrabbit 2.4.0,但无法更新已使用以下方式导入的XML:
session.importXML(node.getPath(), is, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
session.save();
I have the following code that does the XML updating: 我有以下代码可以进行XML更新:
public void updateXML(InputStream is, String nodePath)
throws RepositoryException, IOException, NamingException
{
Session session = getSession();
try
{
logger.debug("Updating path '" +nodePath +"'...");
session.importXML(nodePath, is, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING);
session.save();
}
finally
{
if (session != null)
session.logout();
}
}
Assuming I have a the following imported to Jackrabbit under /notes
: 假设我在
/notes
下将以下内容导入到Jackrabbit中:
<?xml version="1.0"?>
<note xmlns="http://testuri.org/note"
xsi:schemaLocation="http://testuri.org/note file:///path/to/note.xsd"
xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<id>123</id>
<to>Me</to>
<from>You</from>
<heading>Meeting at five</heading>
<body>With this you are hereby invited to the important meeting at five.</body>
</note>
Why does the following code to update the XML not work: 为什么以下代码无法更新XML:
InputStream is = getClass().getClassLoader().getResourceAsStream("note-update.xml");
serviceXML.updateXML(is, "//notes");
and I get the following error: 我收到以下错误:
org.apache.jackrabbit.spi.commons.conversion.MalformedPathException: '//notes' is not a valid path. double slash '//' not allowed.
I do however have the following imported: 但是,我确实导入了以下内容:
/
/jcr:primaryType = rep:root
/jcr:system
/notes
/notes/jcr:primaryType = nt:unstructured
/notes/note:note
/notes/note:note/xsi:schemaLocation = http://testuri.org/note file:///path/to/note.xsd
/notes/note:note/jcr:primaryType = nt:unstructured
/notes/note:note/note:id
/notes/note:note/note:id/jcr:primaryType = nt:unstructured
/notes/note:note/note:id/jcr:xmltext
/notes/note:note/note:id/jcr:xmltext/jcr:xmlcharacters = 123
/notes/note:note/note:id/jcr:xmltext/jcr:primaryType = nt:unstructured
/notes/note:note/note:to
/notes/note:note/note:to/jcr:primaryType = nt:unstructured
/notes/note:note/note:to/jcr:xmltext
/notes/note:note/note:to/jcr:xmltext/jcr:xmlcharacters = Me
/notes/note:note/note:to/jcr:xmltext/jcr:primaryType = nt:unstructured
/notes/note:note/note:from
/notes/note:note/note:from/jcr:primaryType = nt:unstructured
/notes/note:note/note:from/jcr:xmltext
/notes/note:note/note:from/jcr:xmltext/jcr:xmlcharacters = You
/notes/note:note/note:from/jcr:xmltext/jcr:primaryType = nt:unstructured
/notes/note:note/note:heading
/notes/note:note/note:heading/jcr:primaryType = nt:unstructured
/notes/note:note/note:heading/jcr:xmltext
/notes/note:note/note:heading/jcr:xmltext/jcr:xmlcharacters = Meeting at five
/notes/note:note/note:heading/jcr:xmltext/jcr:primaryType = nt:unstructured
/notes/note:note/note:body
/notes/note:note/note:body/jcr:primaryType = nt:unstructured
/notes/note:note/note:body/jcr:xmltext
/notes/note:note/note:body/jcr:xmltext/jcr:xmlcharacters = With this you are hereby invited to the important meeting at five.
/notes/note:note/note:body/jcr:xmltext/jcr:primaryType = nt:unstructured
I have one single entry. 我只有一个条目。
Let's say I would like to update the note with id 123, how would I go about doing that using XPath? 假设我想更新ID为123的注释,我将如何使用XPath进行更新?
Thanks in advance for your help! 在此先感谢您的帮助!
Session.importXml
takes a String path
as its first argument. Session.importXml
将字符串path
作为其第一个参数。 As such, you should specify the location where to import the nodes. 这样,您应该指定导入节点的位置。
In your case, I believe that is /notes
. 就您而言,我相信是
/notes
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.