General XMetaL Discussion

XMetaL Community Forum General XMetaL Discussion Attribute with empty string value

  • tonys

    Attribute with empty string value

    Participants 3
    Replies 4
    Last Activity 10 years ago

    I'm having a problem with a schema (not controlled by me) and am trying to determine whether this is an XMetaL bug or a fault in the schema.

    Here is a simplified version of the schema:

    [code]









    [/code]

    When I use this in XMetaL the attribute selector shows “attr” with a drop-down list containing a single empty item, but selecting this item does nothing. As far as I can tell there is no way other than going into plain-text view to create . Am I missing something?

    If it were up to me I would use yes/no or 0/1 values with an appropriate default, but it's not my choice.

    Are there any compelling arguments I can make to say the schema should be changed, or is this something that XMetaL should handle?

    Reply

    Derek Read

    Reply to: Attribute with empty string value

    This is a use case the Attribute Inspector does not support, or put another way, it has a feature that is breaking this (on purpose). When you set the value for any attribute to “” (empty string) the Attribute Inspector “helpfully” removes the attribute (entirely). This behaviur cannot be altered with any settings.

    The reason this feature is in the product (implemented around 3.0) is due to client requests (actually many complaints).

    Your particular case seems unique (no complaints that I recall and no official requests to implement an alternative). I could see us implementing some option but I think we'd need to have some serious demand for it.

    Changing the Schema to be more “normal” (as you suggest) is one option but perhaps the best solution is to add a script to On_Before_Document_Save or On_Before_Document_Validate that adds the value for any elements that don't already have anything set. Then users only need concern themselves with setting the value if they need it to have a “real” string value.

    Reply

    tonys

    Reply to: Attribute with empty string value

    Yes, I see that this is a consequence of the attribute inspector treating an empty string and “missing” as equivalent, and also that this is the best behaviour in most cases.

    Unfortunately adding/removing the attributes won't work. In this case it's a boolean: either the attribute is missing or has an empty string value. I'll have to tell them to either use plain-text or add a customisation (like an inline form with a checkbox).

    I have one suggestion that would help a bit in this case: could the attribute inspector distinguish attributes that were missing from those with an empty string value? Maybe the name could be displayed with a different style for missing attributes.

    Reply

    Derek Read

    Reply to: Attribute with empty string value

    The Attribute Inspector can't really help distinguish things here as it has no way to distinguish the to in its UI.
    You might be able to do something with CSS though.

    For scripting there is DOMElement_object.hasAttribute() which allows you to check whether an attribute is present, even if it is set to “”. That might be useful in any scripting solution.

    So, this attribute is really meant to be used as a boolean option? That doesn't seem very user friendly to me (ie: easy to distinguish, even when check the XML source).

    Reply

    tonys

    Reply to: Attribute with empty string value

    I spoke too soon – I was concentrating on editing and didn't get as far as validating. When I try to validate a document where the attribute value is an empty string I get:

    “Empty attribute value. An attribute value literal can only be empty for a CDATA attribute.”

    This looks like a bug to me, unless there is something in the XSD specification that says an empty string cannot occur in an enumeration.

    BYW, I couldn't agree more that this is bad data design, but unless I can prove that it's invalid there's nothing I can do about it. Please don't suggest I request a schema change, because I've been told that's not an option.

    Reply

  • You must be logged in to reply to this topic.

Lost Your Password?

Products
Downloads
Support