Personal tools
You are here: Home Documentation Tutorials XML in Plone with Marshall Creating New Entries with CTR
Support

Get Help

Join our chat rooms or support forums if you have more specific questions.

Plone Training
Learn how to design, build, and deploy a website in Plone through one of the numerous Plone training sessions around the world.
Find Plone training…
 
Document Actions

Creating New Entries with CTR

Loading a new XML file should create the correct content type. The Content Type Registry helps us.

Paul Everitt

Marshall lets you save and load Plone content using XML. As a configurable system, it has lots of options. This hands-on how-to shows exactly what to do to make the basics work.
Page 5 of 6.

As shown, editing existing entries was straightforward.  Creating new content in Plone based on external XML files is more problematic.  Namely, what content type should we use for the new resource?

As this isn't a one-size-fits-all situation, Marshall approaches this with configurability in mind.  For mortals like me, choice means confusion.  So this first example shows the simplest possible way to make it work, albeit in a clumsy-to-use fashion.

For this example, we will set a policy that any XML file ending in .atxmlpage will be used to create a Page resource.  The id of that resource will come from the rest of the filename.

The CMF's Content Type Registry is responsible for policies related to file extensions.  This tool can be reached via the ZMI in the portal root under the name "content_type_registry".

  1. Click on content_type_registry tool in ZMI.
  2. Scroll to the bottom.
  3. Add a predicate with a name such as atxmlpage, using Extension as the predicate type in the drop down, and click Add.
    Add CTR Predicate
  4. After saving, change the settings. Set the extensions value to atxmlpage and the content type in the drop-down to Page, then click Change.
    CTR Predicate Editing

The content type registry is now setup.  On your local disk, create a file somewhere named mynewxmlpage.atxmlpage and give it contents as shown below:

<?xml version="1.0" ?>
<metadata xmlns="http://plone.org/ns/archetypes/"
xmlns:cmf="http://cmf.zope.org/namespaces/default/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:xmp="adobe:ns:meta">
<cmf:type>
Document
</cmf:type>
<dc:title>
My first page from XML
</dc:title>
<dc:description>
Congratulations! You have successfully installed Plone.
</dc:description>
<field id="text">
<![CDATA[
<h2>Initial Content</h2>
<p>This content came from an XML file on disk.</p>
]]>
</field>
</metadata>

Save this file, then return to cadaver.  In the top folder of your Plone site, use cadaver to add the file:

put mynewxmlpage.atxmlpage

cadaver uploads the file to Plone.  The CTR sees the extension and knows to create a Page (Document) using the ATXML marshaller, which reads the XML file for all the initial settings.

In Plone you can now go to the URL http://localhost:8080/atxml/mynewxmlpage.atxmlpage and see your new page.

Sure, there are a bunch of caveats to note:

  1. Be very careful to ensure you don't have a field with id="id" in your upload, nor a uid entry.
  2. Would be nice if the .atxmlpage extension disappeared.
  3. If you want to see all the settings, such as dc:subject and workflow state, that you can serialize to XML, go change some things on an existing Page and open it via cadaver.  There's lots there!  Sidnei's XML format was meant to capture lots of semantics.
  4. In a potential future addition to this how-to, I'll cover how to use cmf:type in the XML to create different types without the use of crazy file extensions.


 
by Paul Everitt last modified January 24, 2006 - 13:11
Contributors: Paul Everitt, Sidnei da Silva
All content is copyright Plone Foundation and the individual contributors.

Beware:

Posted by David Ray at May 18, 2006 - 21:51

When playing around with this, I discovered a flaw in how the Contributor and Creator fields interact with the Marshaller. Bug entered here: http://plone.org/products/marshall/issues/3/

Basically, to have the tutorial work, ensure that you either 1) do not include dc:creator and dc:contributor fields, or ensure they are single word entries per element, as anything else will break the creation process.

Thanks for letting me know

Posted by Paul Everitt at May 19, 2006 - 06:28
I'll take a look at it. In the meantime, can you send me an email? The reply feature doesn't let me know your email address. I am paul at zeapartners dot org.

For any issues with the web site functionality, please file a ticket.

Please consult the policy on plone.org content if you want your content published on this site.

Servers and hosting by