2

我正在使用 Jackrabbit 2.4.0,并且无法更新已使用以下命令导入的 XML:

session.importXML(node.getPath(), is, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
session.save();

我有以下执行 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();
    }
}

假设我将以下内容导入到 Jackrabbit 下/notes

<?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>

为什么以下更新 XML 的代码不起作用:

    InputStream is = getClass().getClassLoader().getResourceAsStream("note-update.xml");

    serviceXML.updateXML(is, "//notes");

我收到以下错误:

    org.apache.jackrabbit.spi.commons.conversion.MalformedPathException: '//notes' is not a valid path. double slash '//' not allowed.

但是,我确实导入了以下内容:

/
/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

我只有一个条目。

假设我想更新 id 为 123 的便笺,我将如何使用 XPath 来做呢?

在此先感谢您的帮助!

4

1 回答 1

1

Session.importXml将 Stringpath作为其第一个参数。因此,您应该指定导入节点的位置。

在你的情况下,我相信是/notes.

于 2012-03-26T16:07:29.020 回答