Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Doogie Talons 183 posts 318 karma points
    Mar 23, 2012 @ 17:26
    Doogie Talons
    0

    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

  • Douglas Ludlow 210 posts 366 karma points
    Mar 23, 2012 @ 17:45
    Douglas Ludlow
    0

    The method is still there in Razor:

    System.Xml.XPath.XPathNodeIterator umbraco.library.GetXmlDocumentByUrl(string Url)
  • Doogie Talons 183 posts 318 karma points
    Mar 23, 2012 @ 17:54
    Doogie Talons
    0

    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


  • Douglas Ludlow 210 posts 366 karma points
    Mar 23, 2012 @ 18:04
    Douglas Ludlow
    0

    Right, that's what the method returns. This is how I use it:

    dynamic xml = new DynamicXml(umbraco.library.GetXmlDocumentByUrl("http://example.com/page.xml"));
    @xml.propertyName

     

     

  • Doogie Talons 183 posts 318 karma points
    Mar 23, 2012 @ 22:52
    Doogie Talons
    0

    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 ?

  • Douglas Ludlow 210 posts 366 karma points
    Mar 23, 2012 @ 23:11
    Douglas Ludlow
    4

    xmlv becomes properties. Here, this should help you out some. I just tested it:

    @using umbraco.MacroEngines
    @inherits DynamicNodeContext
    @try
    {
    dynamic xmlv = new DynamicXml(umbraco.library.GetXmlDocumentByUrl("http://1.rhf1.com/xml/fe2009.php"));

    <ul>
    @foreach (var property in xmlv)
    {
    <li>
    <p>
    @foreach (var item in property)
    {
    @item.InnerText<br />
    }
    </p>

    @* or to access them individually: *@

    <p>
    @property.AgentID<br />
    @property.County<br />
    @property.Area<br />
    @property.Type<br />
    @property.Status<br />
    @property.Reference<br />
    @property.Name<br />
    @property.Location<br />
    @property.Price<br />
    @property.AgencyFees<br />
    @property.Summary<br />
    @property.Description<br />
    @property.Pool<br />
    @property.Land<br />
    <em>...</em>
    </p>
    </li>
    }
    </ul>
    }
    catch (Exception e)
    {
    @e.ToString()
    }
  • Doogie Talons 183 posts 318 karma points
    Mar 23, 2012 @ 23:27
    Doogie Talons
    0

    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.

  • Doogie Talons 183 posts 318 karma points
    Mar 27, 2012 @ 15:11
    Doogie Talons
    0

    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... 

  • Douglas Ludlow 210 posts 366 karma points
    Mar 27, 2012 @ 16:17
    Douglas Ludlow
    0

    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...

  • Doogie Talons 183 posts 318 karma points
    Mar 27, 2012 @ 16:42
    Doogie Talons
    0

    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.

  • Douglas Ludlow 210 posts 366 karma points
    Mar 27, 2012 @ 16:55
    Douglas Ludlow
    0

    Yeah, make sure you have the MVC framework installed so that VS will pick up on the razor (cshtml) syntax. Good luck!

  • Doogie Talons 183 posts 318 karma points
    Mar 28, 2012 @ 11:17
    Doogie Talons
    0

    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 0;
      
      
      
      // configuration
      var itemsPerPage String.IsNullOrEmpty(Parameter.ItemsPerPage10 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 == 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(>=(currentPage*itemsPerPage&<(currentPage*itemsPerPage+itemsPerPage))
        {
          <li>@i @item.Name</li>
        }i++;
                   }
      </ul>

      <class="pagingPages">
        @{
      // Google style paging links
        if (currentPage 0{
          <href="?page=@(currentPage)">&laquo@previousLabel</a>
        else {
          <span class="pagingDisabled">&laquo@previousLabel</span>
        }
        
        var Pages Enumerable.Range(1(int)numberOfPages);
        foreach(var number in Pages{
          if (number-!= currentPage{
          <href="?page=@number">@number</a>
          else {
          @number
          }
          @Html.Raw("&nbsp&nbsp");
        }

        if (currentPage Pages.Count()-1{
          <href="?page=@(currentPage+2)">@nextLabel &raquo;</a>
        else {
          <span class="pagingDisabled">@nextLabel &raquo;</span>
        }
      }
      </p>
    }

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies