«»

JCR Deep Dive

XML Import and Export

The JCR natively supports the import and export of content into XML. It defines two XML formats, the system view and the document view. While the system view is targeted to be a complete format for replicating the repository content, the document view provides a human-readable XML format, at the expense of completeness. The document view is hence a subset of the system view.

The two XML formats further greatly differentiate. The system XML format is a namespace-aware, generic XML format which adheres to a pre-defined DTD. Nodes, for example, are expressed through the tag sv:node, as demonstrated in the following example:

<?xml version="1.0" encoding="UTF-8"?>

<sv:node xmlns:jcr="http://www.jcp.org/jcr/1.0" 

xmlns:nt="http://www.jcp.org/jcr/nt/1.0"

xmlns:sv="http://www.jcp.org/jcr/sv/1.0" 

xmlns:xs="http://www.w3.org/2001/XMLSchema"

xmlns:fn="http://www.w3.org/2005/xpath-functions" 

xmlns:fn_old="http://www.w3.org/2004/10/xpath-functions"

xmlns:mix="http://www.jcp.org/jcr/mix/1.0" 

xmlns:samples="http://www.jtoppe.com/samples" 

xmlns:rep="internal"

sv:name="node">

<sv:property sv:name="jcr:primaryType" sv:type="Name">

<sv:value>samples:teaser</sv:value>

</sv:property>

<sv:property sv:name="jcr:uuid" sv:type="String">

<sv:value>dac260e8-bc54-466e-8874-2da96a219c25</sv:value>

</sv:property>

<sv:property sv:name="jcr:created" sv:type="Date">

<sv:value>2008-08-18T13:06:16.236-04:00</sv:value>

</sv:property>

<sv:property sv:name="samples:title" sv:type="String">

<sv:value>sample title</sv:value>

</sv:property>

</sv:node>

The document view explicitly is not a generic format, but rather an explicit XML format. Instead of utilizing generic tags, unique tags are created for each node with the name of the node as the following example shows:

<?xml version="1.0" encoding="UTF-8"?>

<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" 

xmlns:nt="http://www.jcp.org/jcr/nt/1.0"

xmlns:sv="http://www.jcp.org/jcr/sv/1.0" 

xmlns:xs="http://www.w3.org/2001/XMLSchema"

xmlns:fn="http://www.w3.org/2005/xpath-functions" 

xmlns:fn_old="http://www.w3.org/2004/10/xpath-functions"

xmlns:mix="http://www.jcp.org/jcr/mix/1.0" 

xmlns:samples="http://www.jtoppe.com/samples"

xmlns:rep="internal"

jcr:primaryType="rep:root">

<folder jcr:primaryType="samples:folder" jcr:uuid="b583a22b-5af7-4db8-b880-64f841c7d09e"

jcr:created="2008-08-18T13:39:12.769-04:00">

<node jcr:primaryType="samples:teaser" jcr:uuid="ae09589f-6a76-47c7-bca8-e86c7d70f3d5"

jcr:created="2008-08-18T13:39:12.769-04:00" samples:title="first title"/>

<node jcr:primaryType="samples:teaser" jcr:uuid="50d454f4-5ce7-4858-af43-4e5b5a900950"

jcr:created="2008-08-18T13:39:12.769-04:00" samples:title="second title"/>

</folder>

</jcr:root>

Export of content is provides by the Session.exportSystemView() and Session.exportDocumentView() methods, whereas import is provided by Session.importXML(). The import method automatically detects whether the passed in XML is a system or document view.

«»

Comments

4 Responses to “JCR Deep Dive”

  1. Duncan Reade on January 30th, 2009 8:54 am

    First, thank you for providing this very informative site. And Secondly, just in case it has not been brought to your attention: the URI links to the http://www.jcp.org/ site are out of date (used in section 3. Defining Content).

    Regards
    Duncan Reade

  2. Thomas Einwaller on March 13th, 2009 3:20 am

    Thanks for that great post.

    It seems node type folder is missing?

  3. Yasser on June 12th, 2009 7:06 am

    Really good post.. thanks for the effort

  4. Bruno Dusausoy on October 22nd, 2009 6:50 am

    Hi, great article.
    But as Thomas said previously, it seems you forgot to put the node type “samples:folder” definition. It seems it’s a copy/paste of the “samples:content” definition instead.

Leave a Reply




XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

-->