You use getItemAsXML() method of the atg.repository.xml.GetService class to create XML documents from repository items. This method takes a repository item as an input argument and returns a String containing an XML representation of this item. If you write out this String (e.g., to a file), be sure to use the same character encoding that the repository uses.

Some versions of the getItemAsXML() method take additional inputs for specifying a String array of the names of the properties to write out or a String containing the name of the mapping file to use. If you supply only a repository item as input, the method uses the default inclusion rules (described in the Mapping Files section) to determine which properties to include.

By default, GetService writes out an XML document as a single line, because it is intended to be machine-readable. If you want the generated XML to be human-readable, set the indentXMLOutput property of the GetService component to true. The resulting XML will have appropriate line breaks.

Example

Suppose you want to generate XML for a user profile, based on a mapping file named profileMapping.xml. The following code finds the user repository item whose ID is "user747" and generates an XML representation of it:

RepositoryItem userItem = getProfileRepository().getItem("user747",
 "user");
String userAsXML = GetService.getItemAsXML(userItem,"profileMapping.xml");

The following is sample output from this code. The data represents the profile of the user sandy in the Quincy Funds demo:

<user:user xmlns:user="http://www.atg.com/ns/profileMapping/UserProfiles/user"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.atg.com/ns/profileMapping/UserProfiles/user
 profileMapping+UserProfiles+user.xsd " ID="user747">
 <user:securityStatus>0</user:securityStatus>
 <user:actualGoals>long-term</user:actualGoals>
 <user:gender>female</user:gender>
 <user:fundShares>
 <user:integer>500</user:integer>
 <user:integer>220</user:integer>
 <user:integer>180</user:integer>
 <user:integer>260</user:integer>
 </user:fundShares>
 <user:goals>short-term</user:goals>
 <user:dateOfBirth>1976-12-09</user:dateOfBirth>
 <user:pubPrivileges>none</user:pubPrivileges>
 <user:homeAddress>
 <user:homeAddresscontactInfo ID="contactInfo747"/>
 </user:homeAddress>
 <user:numberNewsItems>4</user:numberNewsItems>
 <user:strategy>conservative</user:strategy>
 <user:locale>en_US</user:locale>
 <user:lastActivity>2002-08-14T18:33:49.604</user:lastActivity>
 <user:aggressiveIndex>5</user:aggressiveIndex>
 <user:lastName>Pieta</user:lastName>
 <user:actualStrategy>conservative</user:actualStrategy>
 <user:interests>
 <user:string>tax</user:string>
 <user:string>international</user:string>
 </user:interests>
 <user:id>747</user:id>
 <user:fundList>
 <user:string>/repositories/Funds/en_US/overseas.xml</user:string>
 <user:string>/repositories/Funds/en_US/moneymarket.xml</user:string>
 <user:string>/repositories/Funds/en_US/growth.xml</user:string>
 <user:string>/repositories/Funds/en_US/growthincome.xml</user:string>
 </user:fundList>
 <user:email>sandy@example.com</user:email>
 <user:password>d686a53fb86a6c31fa6faa1d9333267e</user:password>
 <user:registrationDate>1999-04-15T00:00:00.0</user:registrationDate>
 <user:userType>investor</user:userType>
 <user:member>true</user:member>
 <user:brokerId>734</user:brokerId>
 <user:numberFeatureItems>3</user:numberFeatureItems>
 <user:login>sandy</user:login>
 <user:guests>false</user:guests>
 <user:brokers>false</user:brokers>
 <user:investors>true</user:investors>
</user:user>
Namespaces

Notice that information about the XML Schema for this data is included in the user:user tag at the beginning of the document:

xsi:schemaLocation="http://www.atg.com/ns/profileMapping/UserProfiles/user
 profileMapping+UserProfiles+user.xsd "

The xsi:schemaLocation attribute specifies the URL and name of the Schema file. The Schema filename (profileMapping+UserProfiles+user.xsd) is determined by the name of the mapping file (profileMapping.xml), the name of the repository (UserProfiles), and the item descriptor (user). If no mapping file is used to create the document, the Schema filename indicates the repository and item descriptor. If you want the Schema filename to include the entire pathname, set the appendRelativeSchemaLocation property of the GetService component to true. This is especially important if you’re using an external Schema verification tool, which will generally need the complete pathname to find the Schema file.

If you use a mapping file when you create an instance document, you should be sure to supply the name of this mapping file to the generateXMLSchema command (using the –mappingFile argument) when you generate the Schema. Otherwise the actual Schema filename will not match the name in the xsi:schemaLocation tag, and the Schema may not accurately reflect the data in the instance document; as a result, you may not be able to validate the data when reading it into a remote system (or reading it back into Dynamo using AddService). Note also that if your call to getItemAsXML() includes an input argument that specifies the names of properties to write out, the Schema will not accurately reflect the data in the instance document, so validation will not be possible.

To avoid any conflict between tag names, the XML tags in the generated instance document are named using the convention itemType:propertyName; for example the user:userType tag stores the value of the userType property of the user item type. If the addItemTypeToPropertyNames property of the RepositoryXMLTools component that GetService points to is set to true, the tags are named using the convention itemType:itemType.propertyName; in this case, the tag name would be user:user.userType. By default addItemTypeToPropertyNames is set to true, because the resulting XML is less likely to result in naming collisions.

 
loading table of contents...