You use the addItem() method of the atg.repository.xml.AddService class to create new repository items from XML documents. This method takes an XML document as an input argument and returns a repository item. The XML document can be in the form of a String, a, or a The method examines the schemaLocation attribute in the XML document to determine if there is a mapping file associated with the document. Some versions of the method take additional arguments for specifying how to handle missing or empty tags, and whether the data should be validated against a Schema.

For some examples of how a repository item might look in XML document form, see the <ATG9dir>/RL/Example/j2ee-apps/example/web-app/public directory. The Repository Loader (RL) module also includes a page you can use to generate XML documents from existing repository items. This page is located at <ATG9dir>/RL/Example/j2ee-apps/example/web-app/itemAsXml.jsp.

Note that addItem() cannot create new read-only elements in a repository. By default, any data in the instance document that corresponds to a read-only element in the repository is silently ignored. If you want addItem() to log a warning each time it skips a read-only element, set the logWarningOnReadOnly property of the AddService component to true.

Validating the Data

The addItem() method can optionally validate the data in an XML instance document against the Schema specified in the instance document. Validation is enabled or disabled by the validate property of the AddService component. By default, this property is set to false, because validation slows down processing of the document. To enable validation, set the validate property to true.

The addItem() method can also take a Boolean argument to specify whether to validate the document. The value of this argument overrides the validate property. If you do not specify this argument, addItem() uses the validate property to determine whether to validate the document.

If you are confident that your data is valid, you can disable validation, and the instance document will be processed more quickly. However, if the data turns out to be invalid, the invalid data may be written to the repository. If you enable validation and the data is invalid, addItem() does not write the contents of the instance document to the repository.

loading table of contents...