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.

Pages: 1 2 3 4 5 6 7 8 9 10 11