Copied to clipboard

Flag this post as spam?

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


  • andrew shearer 510 posts 659 karma points
    Oct 26, 2011 @ 06:02
    andrew shearer
    0

    check property/element exists [dynamicXml]

    I'm using a uCompoents Url Picker on my doctype, so within my razor scipt i'd like to check for the existance of a property (actually, its an element) as follows:

    @myNode.MyUrlPicker.Url

    if "url" doesn't exist then razor will blow up rather than returning null. Is it possible for DynamicXml and DynamicNode to return null when something doesn't exist rather then blowing up?

    I found this post, but it still seems a bit verbose to incorporate this code into my project. it really seems like core logic:

    http://whatis.goingle.me/dynamicxml-propertyhasvalue-implementation-um

     

    thanks!

     

     

  • Dennis Spijkerboer 53 posts 95 karma points
    Oct 28, 2011 @ 09:05
    Dennis Spijkerboer
    0

    Think that the following should work. You can build in an extra string.IsNullOrEmpty for the url if you want to.

    if(myNode.HasValue("MyUrlPicker"))
    {

    }

  • andrew shearer 510 posts 659 karma points
    Oct 30, 2011 @ 20:39
    andrew shearer
    0

    i don't think that works but will re-try.

    HasProperty, HasValue and IsNull where the first things i tried from the cheatsheet.

     

  • MK 4 posts 55 karma points
    Nov 29, 2011 @ 11:12
    MK
    0

    Hi Andrew,

     

    That code is mine, it's purpose is to handle Dynamic XML specifically.

    I also tought it was a lot of code for such a basic need and that's why I shared it. I'm not sure if nowadays it's still that hard to check if a proprty exists, at that time what we found was that if we changed the uComponent data type to save as CSV it would come in a much easier to handle DynamicNode format. Could that be your case?

     

    Best regards,

    JRA

  • andrew shearer 510 posts 659 karma points
    Nov 29, 2011 @ 21:17
    andrew shearer
    0

    I think its just the nature of XML that all these types of checks are required.. My point was to have your code incorporated into the ucomponents codebase rather than having to use it as a separate helper function.

Please Sign in or register to post replies

Write your reply to:

Draft