Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > missing top level element in XML web part View modes: 
User avatar
Member
Member
garios - 1/23/2011 5:17:45 PM
   
missing top level element in XML web part
Hi!

I can't figure it out this one. I am using version 5.5R2 and I am trying to build a very simple XML list from a specific documents list, so I have a page with a DocumentDataSource and an XML Repeater, the logic works but I am getting an error "Only one top level element is allowed in an XML document. " because I can't find a way to include the top level element, so the repeater works and it does what is supposed to do, but how do I add the root element for the generated XML page?

Thanks for your help!

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 1/28/2011 3:15:37 AM
   
RE:missing top level element in XML web part
Hi,

Using following transformation the root element will be set based on NewsID column dynamically - the HeaderXML and FooterXML property will be overwritten (in the xml tag cannot be number, therefore the orange t was edded in the code ). In case you will use some title column, the t is not needed.


<%@ Register TagPrefix="cc2" Namespace="CMS.PortalControls" Assembly="CMS.PortalControls" %>
<%@ Register TagPrefix="cc2" Src="~/CMSWebParts/Syndication/Basic/XMLRepeater.ascx" TagName="xml" %>

<script runat="server">
public CMSAbstractWebPart FindWebpart(Control o)
{
if (o is CMSAbstractWebPart)
{
return o as CMSAbstractWebPart;
}
else
{
if (o.Parent != null)
{
return FindWebpart(o.Parent);}
else
{
return null;
}
}
}

public void EditWebPart()
{
CMSAbstractWebPart currentWebpart = FindWebpart(this);
if (currentWebpart != null)
{
string title = ValidationHelper.GetString(DataRowView["NewsID"], "");
((CMSWebParts_Syndication_Basic_XMLRepeater)currentWebpart).HeaderXML = "<t" + title + ">" ;
((CMSWebParts_Syndication_Basic_XMLRepeater)currentWebpart).FooterXML= "</t" + title + ">";
}
}
protected override void OnInit(EventArgs e)
{
EditWebPart();
base.OnInit(e);
}
</script>


<CMS_News>
<NewsID><![CDATA[<%# Eval("NewsID", true) %>]]></NewsID>
<NewsTitle><![CDATA[<%# Eval("NewsTitle", true) %>]]></NewsTitle>
<NewsReleaseDate><![CDATA[<%# Eval("NewsReleaseDate", true) %>]]></NewsReleaseDate>
<NewsSummary><![CDATA[<%# Eval("NewsSummary", true) %>]]></NewsSummary>
<NewsText><![CDATA[<%# Eval("NewsText", true) %>]]></NewsText>
</CMS_News>


Best regards,
Ivana Tomanickova

User avatar
Member
Member
garios - 1/28/2011 4:59:08 AM
   
RE:missing top level element in XML web part
I confirm this solution does address the issue.

Thanks for all your help!