I am working on an extension that must create a component. Until now, my code looks like this:
var item = $models.createNewItem($const.ItemType.COMPONENT);
item.setPublication(pubId);
item.setOrganizationalItem(folderId);
item.setDefaultSubType($const.ComponentSubType.COMPONENT);
item.setSchema(schemaId);
item.setTitle("Test Title");
$evt.addEventHandler(item, "save", HandlerSave);
$evt.addEventHandler(item, "savefailed", HandlerSaveFailed);
$evt.addEventHandler(item, "validatefailed", HandlerValidateFailed);
item.setChanged(true);
item.save(false);
The error I get is: Unable to load XML: XML document must have a top level element.. Unable to update Component (tcm:0-0-0).
I think the problem is creating the xml. I tried with setXml/setContent..., but I don't know how to build the required xml for the component.