Copied to clipboard

Flag this post as spam?

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


  • Jon Behrens 11 posts 131 karma points
    Nov 10, 2023 @ 23:17
    Jon Behrens
    0

    Cast node xml into typed content

    Hello

    I'm using Umbraco 7.8

    I'm doing a table join to fetch some additional information relevant to a node.

    The query returns the additional information plus the xml from cmsContentXml.

    Is there a helper function to cast that xml into an Umbraco node? I would like to use the node.attribute notation rather than having to parse the xml directly.

    I could just use the nodeId with an Umbraco helper method, but that would seem to require a second database hit.

  • Marc Goodson 2149 posts 14354 karma points MVP 8x c-trib
    Nov 12, 2023 @ 22:26
    Marc Goodson
    0

    Hi Jon, seems like a long time ago but had to do something similar in v7 once, and the problem, if I remember correctly was that the XmlPublishedContent was internal in the core.

    For our purposes, though, we were able to copy most of that core implementation into our own custom class that implemented IPublishedContent and could be constructed from the raw XML..

    ...aha, here is a gist...

    https://gist.github.com/darrenferguson/0566dfba66a4a85ace413dbb553fbf04

    Hope that's useful..

    Regards

    Marc

  • Jon Behrens 11 posts 131 karma points
    Nov 13, 2023 @ 21:10
    Jon Behrens
    100

    Thank you, Marc.

    It turns out the easiest way to solve my problem is to load the xml into an XmlDocument and then use DOM methods. Since the page needs to display a string, creating an object is an unnecessary intermediate step.

Please Sign in or register to post replies

Write your reply to:

Draft