Copied to clipboard

Flag this post as spam?

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


  • Thomas Dolberg 74 posts 95 karma points
    Apr 14, 2012 @ 01:54
    Thomas Dolberg
    0

    Get the xml for a node or document

    I have attached an event-handler on 

    Document.AfterPublish -= new Document.PublishEventHandler(Document_AfterPublish);

    in order to work with the published document. The eventhandler gives me the published document-object and I would like to get the xml for the document, but I cannot figure out how to get it from neither the node-object nor the document-object. 

    Looking at the umbraco source, I figured this out: umbraco.presentation.UmbracoContext.Current.Server.ContentXml.Descendants().Single(t => t.Attribute("isDoc") != null && (int)t.Attribute("id") == sender.Id);

    but that relies on the umbraco.config file, and this is not updated yet, when I try to get the xml.

    Is it possible to get the xml directly from a document-object or maybe from the db ?

     

    thanks

    Thomas

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Apr 15, 2012 @ 13:06
    Jeroen Breuer
    0

    You can find the xml in the cmsContentXml table in the database, but I don't know if that is only the published xml.

    You can also get the xml with this code, but it's also only published content:

    umbraco.library.GetXmlNodeById("1051")

    Jeroen

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Apr 15, 2012 @ 13:43
    Lee Kelleher
    1

    Hi Thomas,

    The Document object has a method called "ToXml" which you could use?

    var docXml = sender.ToXml(new XmlDocument(), false);

    The method requires an exsiting XmlDocument, (only used to create new the XmlNode).  The second parameter is "Deep", which you can set to true if you want all published child nodes too.

    Cheers, Lee.

  • Thomas Dolberg 74 posts 95 karma points
    Apr 15, 2012 @ 16:16
    Thomas Dolberg
    0

    Hi Jeroen and Lee,

     

    thanks for your input. I couldn't get Jeroen's suggestion to work when publishing a new document (I guess it is because it has not been published to the xml-file yet), whereas Lee's worked fine.

    I know you guys are some of the most active people on the forum, so maybe you have a suggestion for the problem lying behind why I am trying to get the xml.

    The thing is that I am using Linq2Umbraco (in order to get strongtyped objects) on a fairly large site with approx. 25.000 nodes. I use a static instance of the datacontext and store the Linq2Umbraco-context in cache in order to speed things up. The cache is then cleared when a document/node is updated/created/deleted and then the Linq2Umbraco-datacontext is reloaded. Unfortunately it takes approximately 2,5 minutes for the Linq2Umbraco-context to load. On my site the users can update some of the content without giving them access to the umbraco backend (they can only update a few fields). But when a document is published it takes 2,5 minutes to load reload the datacontext as mentioned before. This is of cource quite a bad user experience. 

    I have tried a few strategies to solve this, but so far without much luck. I have tried updating the datacontext async, but it throws an exception, since Linq2Umbraco cannot handle async operations it seems. I then tried creating a webrequest which would call a url which would create a new datacontext and replace the old one (in order to emulate async operation). But this also fails because the collection is then modified when a page using the context is reloaded (as far as I can tell). Now I am trying to get the xml and then create a strongtyped object and add it to the datacontext without reloading it. I don't know if this will work, but that is my next move.

    I guess you guys have build some quite large Umbraco-sites (maybe even with Linq2Umbraco). Do you have any suggestions on how to handle this scenario?

     

    thanks

    Thomas

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Apr 15, 2012 @ 17:28
    Jeroen Breuer
    0

    Hi Thomas,

    Unfortunately I don't use Linq2Umbraco anymore because of this problem. I really love strongtyped objects in Umbraco, but Linq2Umbraco already get's slow with 2000 nodes. I think the best way to improve performance is to use something else instead of Linq2Umbraco. Perhaps this topic can help: http://our.umbraco.org/forum/developers/api-questions/18933-Query-multiple-websites

    Jeroen

Please Sign in or register to post replies

Write your reply to:

Draft