Home Forums General XMetaL Discussion How to Disallow Empty Elements? Reply To: How to Disallow Empty Elements?


Reply to: How to Disallow Empty Elements?

Thank you for the detailed reply (btw, we also have a support agreement, but I figured someone else might find this useful, so I decided to just ask her instead).

We're already using the PI, like so:


I'm not sure how it's implemented, but doubleclicking on that actually opens a dialog that lets you select something.
But we have issues with some users editing the xref contents (label), believing they could change the target, or deleting the label alltogether (thus creating an empty element, which causes problems for us elsewhere).

To make sure they don't change existing xref elements, this works like a charm:

[code]var elemName = “xref”;
var rng = ActiveDocument.Range;
while(rng.MoveToElement(elemName)) {
rng.ReadOnlyContainer = true;

As for the “business rule validation,” I have found [url=http://forums.xmetal.com/index.php?topic=319.0]this great example[/url] and have adapted the code to our needs, more or less.
Here is the relevant code:

[code]var cd = Application.CheckData;
var elem = cd.Element;
var name = elem.tagName; if(name == “xref”) {
var value = cd.Value;
if(value == null || value == “”) {
cd.ValidationMsg = “Empty xrefs are not allowed. If the xref is marked as read-only, please delete it and create a new one.”;

But unfortunately value is always “” (empty string).
Can this be related to the PI? Maybe the macro doesn't even see the contents?

The code is quite difficult to debug as I basically have to resort to message boxes and the likes. If I could step through it line by line and inspect variables, it would be much easier. I guess there's no way to achieve that?
I also couldn't even extract the properties from the variables at runtime (JSON.stringify(elem) etc.).

And like I said, we're currently using XMetaL Author 9, but we're working on upgrading to version 13. Are there any new features that would make handling this easier?

Thank you.