Как вы обновляете содержимое XML в Jackrabbit, используя запрос XPath? - PullRequest
2 голосов
/ 26 марта 2012

Я использую 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

У меня есть одна запись.

Допустим, я хотел бы обновить заметкус идентификатором 123, как бы я поступил так с помощью XPath?

Заранее спасибо за помощь!

1 Ответ

1 голос
/ 26 марта 2012

Session.importXml принимает строку path в качестве первого аргумента. Таким образом, вы должны указать место, куда импортировать узлы.

В вашем случае, я считаю, что это /notes.

...