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
9 Responses to “JCR Deep Dive”
Leave a Reply
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
Thanks for that great post.
It seems node type folder is missing?
Really good post.. thanks for the effort
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.
Really great article.
With regards to the missing definition for samples:folder, I believe the below works.
[samples:folder] > samples:content
// accept any subnodes of type samples:content
+ * (samples:content) multiple
I adapted this from the example in the CND in a nutshell section of this blog.
Thanks! I need to spend some time updating my blog at some point :-)
Great content. Are there some good interative builder for CND Types ? Would be interesting links
Building an interactive builder shouldn’t be that hard. Back when I worked for CoreMedia we had a tool that would take the XMI from any old UML tool and XSLT’ed it to a content definition file. Wasn’t CND but XML, but same idea.
Java Content Repository Deep Dive…
I found an interesting “article” online about Java Content Repositories (JCR). I’m going to look into this further because it may be useful as a replacement to our current JPA workflow. JCR supports many features that should be useful,……