Copied to clipboard

Flag this post as spam?

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


  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Feb 25, 2010 @ 13:01
    Jeroen Breuer
    0

    node.GetProperty on a custom datatype

    Hello,

    I've got a custom datatype which saves the value as an xml file inside the umbrac.config file. Here is an example:

          <data alias="emailCompany">        
        <Email>
              <Checked>True</Checked>
              <Field name="SenderName">Termors</Field>
            </Email>
          </data>

    If I want to read this data with node.GetProperty(emailCompany).Value I always get null back. I looked into the source code how this data is load:

    In the Node constructor:

    // load data
    foreach (XmlNode n in _pageXmlNode.SelectNodes("./data"))
           _properties.Add(new Property(n));

    Property constructor:

    public Property(XmlNode PropertyXmlData) {
                if (PropertyXmlData != null) {
                    // For backward compatibility with 2.x (the version attribute has been removed from 3.0 data nodes)
                    if (PropertyXmlData.Attributes.GetNamedItem("versionID") != null)
                        _version = new Guid(PropertyXmlData.Attributes.GetNamedItem("versionID").Value);
                    _alias = PropertyXmlData.Attributes.GetNamedItem("alias").Value;
                    _value = xmlHelper.GetNodeValue(PropertyXmlData);
                } else
                    throw new ArgumentNullException("Property xml source is null");
            }

    It doens't look in the elements inside the data element. What is the best way to load this data? Should I just read the umbraco.config file directly or create a class which inhertis from Node and do some coding in there to fetch the data. Has anyone else had this before?

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Feb 25, 2010 @ 13:13
    Ismail Mayat
    0

    Jeroen,

    If you are on .net35 may be try extension method see Darrens tip http://www.darren-ferguson.com/2010/2/25/quick-tip-using-extension-methods-with-umbraco-and-net-35.aspx write your own which can handle the custom datatype xml?

    Regards

    Ismail

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Feb 25, 2010 @ 13:38
    Jeroen Breuer
    0

    Hi Ismail,

    That would be a good idea, but the problem is I need the xml data from the node. This is stored inside private XmlNode _pageXmlNode; and since it's private I can't reach it. I think it's best to create my own class similar to the Node class, but with an method called GetPropertyXml which loads the property as xml. This might acutally be good for the default umbraco Node object. Will this problem be solved in 4.1 with Linq to Umbraco?

    Jeroen

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Feb 25, 2010 @ 17:14
    Dirk De Grave
    0

    Jeroen,

    what db type are you using for your custom datatype? I think there's a difference in using ntext or nvarchar (don't remember by heart, but think one stores the value as is, the other as a cdata section? Maybe that can help?

     

    Cheers,

    /Dirk

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Feb 26, 2010 @ 08:23
    Jeroen Breuer
    0

    The db type is an ntext. If I use an nvarchar I get an error because the stored xml is too big. Eventually I solved it with the following code:

    //Get the current xml node.
    XmlNode n = ((IHasXmlNode)library.GetXmlNodeCurrent().Current).GetNode();
    
    //Convert the current xml node to a XDocument;
    XDocument xmlDocument = XDocument.Load(new XmlNodeReader(n));

    Once I have the xmlDocument I use LINQ to XML to get the data I need.

Please Sign in or register to post replies

Write your reply to:

Draft