Copied to clipboard

Flag this post as spam?

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


  • trfletch 598 posts 604 karma points
    Jan 25, 2010 @ 15:16
    trfletch
    0

    Pulling data from Umbraco database - how easy?

    How easy is it to pull data from an Umbraco database to display in another Umbraco site or even another non-Umbraco asp.net site? The reason I ask is because I have a customer that wants to created a recruitment based website which I thought I could do in Umbraco fairly easily but the issue is that later on down the line they are going to need to use the data from this website on other websites that may or may not be Umbraco sites.

    Taking a quick look at the database of the Umbraco website I can see that the data is not stored in a very straight forward manner (i.e. it uses GUID;s etc) therefore how easy is it going to be for an asp.net developer who has absolutely no experience or knowledge of Umbraco to pull the data (or possibly even write it) from the Umbraco website database?

  • dandrayne 1138 posts 2262 karma points
    Jan 25, 2010 @ 15:18
    dandrayne
    1

    I'd have thought that it would be easier to use your umbraco site to generate xml/rss, which you can then pull in to your new site and transform as required. 

  • atze187 160 posts 215 karma points
    Jan 25, 2010 @ 15:22
    atze187
    0

    Reading the umbraco database directly from a 3rd app is evil (at least, I could never encourage that). I would recommend establishing a webservice which exposes the data in question to the world. Writing would a no go.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jan 25, 2010 @ 15:24
    Dirk De Grave
    0

    +1 on a webservice oriented solution, only expose what's really necessary!

     

    Cheers,

    /Dirk

  • Stephan Lonntorp 195 posts 212 karma points
    Jan 25, 2010 @ 15:26
    Stephan Lonntorp
    0

    If writing a web service solution is out of scope, you could easily just write an xslt macro that renders your data as XML. That would enable you to consume that data in whatever way you'd like, and wouldn't limit you to the format provided by rss/atom.

  • Edward Dudley 80 posts 121 karma points
    Jan 25, 2010 @ 15:30
    Edward Dudley
    0

    If you just need the site XML content then you could write a macro that outputs the whole site XML and put it on a page.  This would then work like a webservice.  Your other site could call this "webservice" and parse the XML appropriately.

    Post back if you need example code to pull the Umbraco XML.  I'm sure it's out there on the net too.

    This would be how I would expose content - you'd have to write something else if you wanted to expose templates, users, etc. though.

  • Edward Dudley 80 posts 121 karma points
    Jan 25, 2010 @ 15:30
    Edward Dudley
    0

    Cross posted!  Great minds think alike!

  • trfletch 598 posts 604 karma points
    Jan 25, 2010 @ 15:33
    trfletch
    0

    Hi,

    Wow, thanks for all the quick responses, Edward, I would only need to expose the content, how would I go about writing a macro to output the XML and also pulling it back in to another site?

    Also what about pulling it into another Umbraco site?

  • atze187 160 posts 215 karma points
    Jan 25, 2010 @ 16:10
    atze187
    0

    If you want to sync multiple sites from one "master" site (that maybe served using umbraco) to some "client" sites (which do not necessarily run on umbraco), you should use umbraco api to send updates to the "client" sites whenever the content in question is updated (the client sites would need a webservice interface themselves).

  • dandrayne 1138 posts 2262 karma points
    Jan 25, 2010 @ 16:34
    dandrayne
    1

    It might not be the best idea to output the whole site for a couple of reasons, but xml is easy in umbraco as all content is xml anyhow.

    if you just create a template with just

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

    Then an xslt macro with something like

    <pages>
    <xsl:for-each select="$currentPage/node">
    <page>
    <name><xsl:value-of select="current()@nodeName" /></name>
    </page>
    </xsl:for-each>
    </page>

    You'll get a very simple xml file listing all nodes beneath the current.  This can be extended as much as normal umbraco templates can be, and can be quite powerful

    Dan

  • Edward Dudley 80 posts 121 karma points
    Jan 26, 2010 @ 08:54
    Edward Dudley
    0

    Beat me to it @dandrayne!

    I'd do it slightly differently but I guess it depends on how much of the content you need, etc:

    I'd just do a copy of the node:

    <xsl:copy-of select="$currentPage" />

    Put that in a macro and put it on a page (use @dandrayne's XML declaration above).

    If you want to shift content between two Umbraco sites then maybe Umbraco consierge (pro) would be easier though?

     

  • Edward Dudley 80 posts 121 karma points
    Jan 26, 2010 @ 08:57
    Edward Dudley
    0

    In fact, what might also be useful would be to put this in an alternate template.

    Create a template that has the XML declaration and a macro with the above XSLT.  Call the template "myXml" for example

    Then hit any page on your site and append "?altTemplate=myXml" to the URL.  You should then get the XML representing that node and child nodes.

  • trfletch 598 posts 604 karma points
    Jan 26, 2010 @ 10:56
    trfletch
    0

    Hi Dan,

    Thanks for the response, I tried creating your XSLT but it has a few errors, the first one was was the last </page> tag which I assume should be </pages> but then it throws an error on this line and I'm not sure how it should be:

    20: >>>   <name><xsl:value-of select="current()@nodeName" /></name> <<<

  • trfletch 598 posts 604 karma points
    Jan 26, 2010 @ 12:03
    trfletch
    0

    Ok, I have got my XML output using Edwards suggestion, just wondered how I would make it more specific for example only list node that are a certain document type?

  • trfletch 598 posts 604 karma points
    Jan 26, 2010 @ 12:22
    trfletch
    0

    Sorry just realised I have not got exactly what Edward suggested, I have used the following to list all the nodes XML:

    <xsl:copy-of select="$currentPage/ancestor-or-self::node [@level=1]" />

    but I want to list only node that are Job document type, I tried the following but it did not work, does anyone know where I am going wrong?

    <xsl:copy-of select="$currentPage/ancestor-or-self::node [@level=1 and @nodeTypeAlias='Job']" />
  • dandrayne 1138 posts 2262 karma points
    Jan 26, 2010 @ 12:35
    dandrayne
    0

    It's exactly the same as doing a "normal" template in that

    <jobs>
    <xsl:for-each select="$currentPage/ancestor-or-self::node [@level=1]//node[@nodeTypeAlias='Job']">
    <job>
    <name><xsl:value-of select="current()/@nodeName" /></name>
    </job>
    </xsl:for-each>
    </jobs>

    Will get a list of all nodenames of type job, then you just build from there

    Dan

  • trfletch 598 posts 604 karma points
    Jan 26, 2010 @ 12:46
    trfletch
    0

    Thank you Dan, you're a legend, that is exactly what I need. At least now I can recommend using Umbraco for the solution because I know we can extract the data out easily for use on other websites. Don't mean to be cheeky but I don't suppose you know the answer to my other post about the Ultimate Picker because that is the only thing that is now holding up this project? Thanks again and thanks to everyone else who helped

  • dandrayne 1138 posts 2262 karma points
    Jan 26, 2010 @ 12:57
    dandrayne
    0

    I'll take a look after lunch ^^

  • 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