Frustratingly enough, I don't believe there is anything documented for DynamicXml. Aside from googling "dynamicxml umbraco", if you create a razor script in Visual Studio, you can use the autocomplete feature to see what other properties are available. However, this will not, unfortunately, yield a complete list as DynamicXml objects are meant to be used in a dynamic context where additional methods and properties are available. I guess the true "documentation" is the umbraco source...
Ok thanks. I can see a whole new learning curve on the horizon. I'll fire up vis studio and trail and error for a while. Best thing is I am in no rush :)
I am making some headway but have also cheated with a maths hack. I am sure this is innefficient but there seems to be no helpful definitions on this object.
Here is my code so far. I hope it helps someone else someday with everying owed to Douglas and the folks who wrote the paging example on umbraco 4.7.1
This code takes a xml feed and pages the results.
@using umbraco.MacroEngines
@inherits umbraco.MacroEngines.DynamicNodeContext @{ dynamic pagesToList = new DynamicXml(umbraco.library.GetXmlDocumentByUrl("http://1.rhf1.com/xml/fe2009.php")); int i = 0; // configuration var itemsPerPage = String.IsNullOrEmpty(Parameter.ItemsPerPage) ? 10 : int.Parse(Parameter.ItemsPerPage); var previousLabel = String.IsNullOrEmpty(Parameter.PreviousLabel) ? "Previous" : Parameter.PreviousLabel; var nextLabel = String.IsNullOrEmpty(Parameter.NextLabel) ? "Next" : Parameter.NextLabel;
// paging calculations var numberOfItems = pagesToList.Count(); int currentPage = 1; if (!int.TryParse(HttpContext.Current.Request.QueryString["Page"], out currentPage)) { currentPage = 1; } currentPage--; var numberOfPages = numberOfItems % itemsPerPage == 0 ? Math.Ceiling((decimal)(numberOfItems / itemsPerPage)) : Math.Ceiling((decimal)(numberOfItems / itemsPerPage))+1;
<p> Total Items: @numberOfItems <br /> Items per Page: @itemsPerPage<br /> Pages: @numberOfPages;<br /> Current Page: @(currentPage);<br /> From Item Number: @(currentPage*itemsPerPage)<br /> To Item Number:@(currentPage*itemsPerPage+itemsPerPage) </p>
<ul> @foreach(var item in pagesToList) { if(i >=(currentPage*itemsPerPage) && i <(currentPage*itemsPerPage+itemsPerPage)) { <li>@i : @item.Name</li> }i++; } </ul>
<p class="pagingPages"> @{ // Google style paging links if (currentPage > 0) { <a href="?page=@(currentPage)">« @previousLabel</a> } else { <span class="pagingDisabled">« @previousLabel</span> } var Pages = Enumerable.Range(1, (int)numberOfPages); foreach(var number in Pages) { if (number-1 != currentPage) { <a href="?page=@number">@number</a> } else { @number } @Html.Raw("  "); }
umbraco.library:GetXmlDocumentByUrl('') replacement Help Required.
Any search with XML URL and RAZOR in produces way too much to wade through.
I am replaceing a load of xslts with razor just to get teh hang of it.
But...
what replaces
umbraco.library:GetXmlDocumentByUrl('')
I want to populate a var with the contents of an xml which is hosted online and use it like the @Model.
Cheers
Doogie
The method is still there in Razor:
Thanks I think I need to go back tot he basics :)
I tried the following as a sort of hello world...
@using System;
@using System.Xml;
@inherits System.Xml.XPath.XPathNodeIterator;
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
var targetUrl = umbraco.library.GetXmlDocumentByUrl("http://1.rhf1.com/xml/fe2009.php");
@targetUrl
}
It just spits out MS.Internal.Xml.XPath.XPathSelectionIterator
Right, that's what the method returns. This is how I use it:
Ok I am now getting more lost and I thought this transition would be easy.
I thought I could itterate through the returned value like the @Model
@using System.Xml;
@using System.IO;
@using System.Text;
@using umbraco.MacroEngines;
@inherits System.Xml.XPath.XPathNodeIterator;
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
dynamic xmlv = new DynamicXml(umbraco.library.GetXmlDocumentByUrl("http://1.rhf1.com/xml/fe2009.php"));
@xmlv.properties
}
umbraco.MacroEngines.DynamicXml' does not contain a definition for 'properties'
As you can see from http://1.rhf1.com/xml/fe2009.php properties is the base node of the xml.
Is there no wiki for the definitions of the umbraco specific namespaces ?
xmlv becomes properties. Here, this should help you out some. I just tested it:
Perfect even though I don't need this for a client I really needed to get my head round it. Thanks very much for your response.
Doogie.
Just a quick aside. I am trying to understand the properties and definitions of DynamicXml.
Where do I find them ? I can't find any documentation. I have been messing about with your code and had varying results.
for example I tried mixing it in with the paging example in umbraco 4.7.1 and can't itterate through the results using Skip and Take...
Frustratingly enough, I don't believe there is anything documented for DynamicXml. Aside from googling "dynamicxml umbraco", if you create a razor script in Visual Studio, you can use the autocomplete feature to see what other properties are available. However, this will not, unfortunately, yield a complete list as DynamicXml objects are meant to be used in a dynamic context where additional methods and properties are available. I guess the true "documentation" is the umbraco source...
Ok thanks. I can see a whole new learning curve on the horizon. I'll fire up vis studio and trail and error for a while. Best thing is I am in no rush :)
Doogie.
Yeah, make sure you have the MVC framework installed so that VS will pick up on the razor (cshtml) syntax. Good luck!
I am making some headway but have also cheated with a maths hack. I am sure this is innefficient but there seems to be no helpful definitions on this object.
Here is my code so far. I hope it helps someone else someday with everying owed to Douglas and the folks who wrote the paging example on umbraco 4.7.1
This code takes a xml feed and pages the results.
@using umbraco.MacroEngines
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
dynamic pagesToList = new DynamicXml(umbraco.library.GetXmlDocumentByUrl("http://1.rhf1.com/xml/fe2009.php"));
int i = 0;
// configuration
var itemsPerPage = String.IsNullOrEmpty(Parameter.ItemsPerPage) ? 10 : int.Parse(Parameter.ItemsPerPage);
var previousLabel = String.IsNullOrEmpty(Parameter.PreviousLabel) ? "Previous" : Parameter.PreviousLabel;
var nextLabel = String.IsNullOrEmpty(Parameter.NextLabel) ? "Next" : Parameter.NextLabel;
// paging calculations
var numberOfItems = pagesToList.Count();
int currentPage = 1;
if (!int.TryParse(HttpContext.Current.Request.QueryString["Page"], out currentPage)) {
currentPage = 1;
}
currentPage--;
var numberOfPages = numberOfItems % itemsPerPage == 0 ? Math.Ceiling((decimal)(numberOfItems / itemsPerPage)) : Math.Ceiling((decimal)(numberOfItems / itemsPerPage))+1;
<p>
Total Items: @numberOfItems <br />
Items per Page: @itemsPerPage<br />
Pages: @numberOfPages;<br />
Current Page: @(currentPage);<br />
From Item Number: @(currentPage*itemsPerPage)<br />
To Item Number:@(currentPage*itemsPerPage+itemsPerPage)
</p>
<ul>
@foreach(var item in pagesToList)
{
if(i >=(currentPage*itemsPerPage) && i <(currentPage*itemsPerPage+itemsPerPage))
{
<li>@i : @item.Name</li>
}i++;
}
</ul>
<p class="pagingPages">
@{
// Google style paging links
if (currentPage > 0) {
<a href="?page=@(currentPage)">« @previousLabel</a>
} else {
<span class="pagingDisabled">« @previousLabel</span>
}
var Pages = Enumerable.Range(1, (int)numberOfPages);
foreach(var number in Pages) {
if (number-1 != currentPage) {
<a href="?page=@number">@number</a>
} else {
@number
}
@Html.Raw("  ");
}
if (currentPage < Pages.Count()-1) {
<a href="?page=@(currentPage+2)">@nextLabel »</a>
} else {
<span class="pagingDisabled">@nextLabel »</span>
}
}
</p>
}
is working on a reply...