Developer forum

Forum » Templates » Pure XML output?

Pure XML output?

Rasmus Pedersen
Reply

Can I somehow make my entire output to proper XML?

 

<?xml version="1.0" encoding="utf-8" ?>
<master>
    <!--@ContentPlaceholder-->
</master>

That's my master template.

My output ends up like this:

<?xml version="1.0" encoding="utf-8" />
<master>
blah blah blah, my proper XML stuff here
.
.
.
</master><script type="text/javascript" src="/Admin/Content/JsLib/dw/Analytics.js"></script>
<script type="text/javascript">
//<![CDATA[
var _tr = Dynamicweb.Analytics.Tracker.get_current();
_tr.set_parameters({ sessionID: 'zdwzbrcoqawdeqcps4jgzgbs', pageID: 7, areaID: 1, engagement: 0 });
_tr.add_contentReady(function(sender, args) { _tr.trackVisit(); });
//]]>
</script>
<!-- Exe time: 0,125 :   < (1) >  <PageID (7)>  <Clear content cache>  <Designs/wodnow/XMLPage.parsed.html>  -->

I just want pure, unaltered XML please.
(Notice that it changes the last ? in the XML declaration as well as adding stuff at the end.)


Replies

 
Kenneth Radoor
Reply

bump

I have the same issue, it would be really nice if we could this to work

Then wi could reuse the functionality that DW offers, and would not have to reinvent the wheel :)

In my case i have to render output from ecom, and serve it as a pure xml

 

 
Nicolai Høeg Pedersen
Reply

Ýou can disable the performance comment from mgmt center.

 

Try inserting this in your template:

 

<!--@If(1=2)-->
<!--@Javascripts-->
<!--@EndIf-->

That should remove the tracking script etc.

 
Kenneth Radoor
Reply

thanks

Then there is only one issue left, as Rasmus stated in his post. The xml decleration tag is not valid

<?xml version="1.0" encoding="utf-8" ?>

is turned into

<?xml version="1.0" encoding="utf-8" />

 

 

 

 

 
Mikkel Ricky
Reply

We're working on a fix for the xml declaration being invalid after parsing the template.

Have you tried just creating a very simple xml template rather than using a master page? Using a layout template like

<?xml version="1.0" encoding="utf-8"?>
<root>
	<div id="content" class="dwcontent" title="Main content"></div>
</root>

I get valid xml output (provided that the content is valid xml and ignoring the broken xml declaration).

Are you loading the xml using Ajax or how is it to be used?

Best regards,
Mikkel 

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

I ran into the same issue some time ago, and fixed it with a subscriber:

[Subscribe(Standard.Page.OnOutput)]
public class SetXmlAsOutputForGoogleMerchantFeed : NotificationSubscriber
{
  public override void OnNotify(string notification, NotificationArgs args)
  {
    if (IsFrontend && SomeLogicToDetermineIfThisIsAnXmlPage())
    {
      var localArgs = args as Standard.Page.OnOutputArgs;
      if (localArgs != null)
      {
        localArgs.template.Html = localArgs.template.Html.Replace(" id=\"content-main\"", "");
        HttpContext.Current.Response.ContentType = "text/xml";
        HttpContext.Current.Response.Write("<?xml version=\"1.0\"?>");
      }
    }
  }
}

It's not pretty, but it did the trick. In the SomeLogicToDetermineIfThisIsAnXmlPage I looked at the extension (.xml in my case) of the request, and a page ID. The benefit of this solution is that you can also control the Content Type - XML in this case. A feature I'd like to see added to Dynamicweb.

 

Hope this helps (hopefully just temporary as this should be supported out of the box)

 

EDIT: For this to work, your master page should not have the XML prolog.

 

Cheers,

 

Imar

 
Kenneth Radoor
Reply

Hi Mikkel

I do get valid XML, except for the declaration, so thats all good.

The output is for an external tool, that needs and expects valid XML, so i need to fix the problem.

Ill have a shoot at Imars solution.

Thanks to both of you

 

Kenneth

 

You must be logged in to post in the forum