Is there a way to ignore the root element when using GetListXml
? Take a look at the below code, I check what objData
is and then loop over each result, however I need to ignore the root element ONLY when Settings.TridionPublicationOrStructureGroupId
is a publicationId.
using (var client = new CoreServiceClient("basicHttp"))
{
var objData = (IdentifiableObjectData)client.Read(
Settings.TridionPublicationOrStructureGroupId, new ReadOptions());
XElement sgXml = null;
if (objData is PublicationData)
{
sgXml = client.GetListXml(Settings.TridionPublicationOrStructureGroupId,
new RepositoryItemsFilterData
{
ItemTypes = new[] { ItemType.StructureGroup },
Recursive = true
});
//Ignore the root element??
}
else if(objData is StructureGroupData)
{
sgXml = client.GetListXml(Settings.TridionPublicationOrStructureGroupId,
new OrganizationalItemItemsFilterData
{
ItemTypes = new[] { ItemType.StructureGroup },
Recursive = true
});
}
if (sgXml != null)
{
Log.DebugFormat("Found {0} sg(s)", sgXml.DescendantsAndSelf().Count());
foreach (var sg in sgXml.DescendantsAndSelf()))
{
Console.WriteLine(sg.Attribute("ID").Value);
}
}
}
Is this possible?