I have done a program in Java which sets ItemTypes in Tridion and gets the list of all specified ItemTypes in a Publication. I have used Element to getList of items.
import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPathExpressionException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import com.sdltridion.contentmanager.coreservice.ICoreService;
import com.sdltridion.contentmanager.coreservice.ICoreServiceGetListXmlCoreServiceFaultFaultFaultMessage;
import com.sdltridion.contentmanager.coreservice.ICoreServiceGetSystemWideListXmlCoreServiceFaultFaultFaultMessage;
import com.sdltridion.contentmanager.r6.ArrayOfItemType;
import com.sdltridion.contentmanager.r6.ItemType;
import com.sdltridion.contentmanager.r6.ListBaseColumns;
import com.sdltridion.contentmanager.r6.ObjectFactory;
import com.sdltridion.contentmanager.r6.RepositoryItemsFilterData;
public class RepositoryItemsFilterDataDemo {
public static void getRepositoryItems(ICoreService endpoint) throws ICoreServiceGetListXmlCoreServiceFaultFaultFaultMessage
{
ObjectFactory objectFactory = new ObjectFactory();
ArrayOfItemType itemTypes = objectFactory.createArrayOfItemType();
itemTypes.getItemType().add(ItemType.STRUCTURE_GROUP);
itemTypes.getItemType().add(ItemType.PAGE);
RepositoryItemsFilterData filter = objectFactory.createRepositoryItemsFilterData();
ListBaseColumns baseColumns = ListBaseColumns.EXTENDED;
filter.setRecursive(objectFactory.createItemsFilterDataRecursive(true));
filter.setItemTypes(objectFactory.createItemsFilterDataItemTypes(itemTypes));
filter.setBaseColumns(objectFactory.createListBaseColumns(baseColumns));
Element element = (Element) endpoint.getListXml("tcm:0-29-1", filter).getAny();
System.out.println(element.toString());
NodeList schemaList =element.getElementsByTagName("tcm:Item");
for (int i = 0; i < schemaList.getLength(); i++) {
Element itemXml = (Element) schemaList.item(i);
StringBuffer sb = new StringBuffer();
sb.append("<tcm:Item" + " ");
sb.append("ID = " );
sb.append(itemXml.getAttribute("ID"));
sb.append(" " + "Title = " );
sb.append(itemXml.getAttribute("Title"));
sb.append(" " + "Type = " );
sb.append(itemXml.getAttribute("Type"));
sb.append(" " + "Modified = " );
sb.append(itemXml.getAttribute("Modified"));
sb.append(" " + "FromPub = " );
sb.append(itemXml.getAttribute("FromPub"));
sb.append(" " + "Icon = " );
sb.append(itemXml.getAttribute("Icon"));
sb.append("/>");
System.out.println(sb);
}
}
}
When I debug my program the element object is returning null. But when I run the program the output is displayed as
o/p:
[tcm:ListItems: null]
<tcm:Item ID = tcm:29-2643-4 Title = 000 Effective treatment of .... Type = 4 Modified = 2013-01-31T01:35:17 FromPub = 040 Merck Connect Website Icon = T4L0P1/>
Can any one suggest what might cause this problem and also can any one suggest how can I get the output in XML format like the one in .NET without hard coding the xml format.
.NET output :
<tcm:ListOrganizationalItems xmlns:tcm="http://www.tridion.com/ContentManager/5.0">
<tcm:Item ID="tcm:29-107-4" ParentOrgItemID="tcm:0-29-1" Title="Root" Type="4" Modified="2012-09-14T11:06:07" FromPub="000 WCM Empty Parent" Icon="T4L0P1"/>