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

エントリが1つあります。

ID 123でメモを更新したいとしますが、XPathを使用してそれを行うにはどうすればよいですか?

よろしくお願いします!

4

1 に答える 1

1

Session.importXmlpath最初の引数として文字列を取ります。そのため、ノードをインポートする場所を指定する必要があります。

あなたの場合、それはだと思います/notes

于 2012-03-26T16:07:29.020 に答える