Skip to main content
vze26m98
Known Participant
June 26, 2011
Answered

XMLRules and "the selection"?

  • June 26, 2011
  • 1 reply
  • 9436 views

Hi all-

I'm impressed by the speed of XMLRules over an iteration through the XML tree, but I wonder if it's possible to operate on a user-selection of XML elements with XMLRules? I'm guessing it's not, because a user selection wouldn't necessarily form a tree for an XMLRule to move through.

But is there any way to determine whether a given XML element is part of the current user selection? This information shows up as an underlined element in the Structure window, but I can't seem to find a parallel property in the InDesign object model.

Related to this, but a more general question, is whether the start element for the XMLRules processor can be something other than the root element? All of the published examples start at the root, but is it possible to pass an arbitrary element as the root for use by the processor?

Many thanks!

Charles Turner

This topic has been closed for replies.
Correct answer Dirk Becker

Hi Dirk-

Thanks for your notes. I tried the xpath() method in E4X while I was struggling with namespace issues. ;-) But the real gem in your post for me is the evaluateXPathExpression() method. If it proves fruitful, I'll post my results.

Many thanks! Charles


Don't miss the other single code line in the small print - I still wish the forum would revert to a usable plain text editor.

Dirk

1 reply

John Hawkinson
Inspiring
June 27, 2011

Hi, Charles.

  Dealing with XML is a pain, and dealing with XML in InDesign even more so, and dealing with XML Rules in InDesign's scripting architecture is like the trifecta. I would strongly encourage you to find another way to do what you want, it will likely be easier to write and an order of magnitude easier to maintain.

Can you tell us about the problem you're trying to solve?

In any case, though, if you're dead set on using XML Rules, please take a look at my example from Re: How to shift content with in cell in xml rules table (reply #20). I think it makes it much much easier to use XML Rules in Javascript without all the annoying pain and ugly syntax.

I'm impressed by the speed of XMLRules over an iteration through the XML tree, but I wonder if it's possible to operate on a user-selection of XML elements with XMLRules? I'm guessing it's not, because a user selection wouldn't necessarily form a tree for an XMLRule to move through.

Note that typically one traverses a tree rather than iterating over it.

Anyhow, It seems like the wrong approach -- why not iterate over the list of user-selected subtrees and traverse it with __processRuleSet ? Or you could move them into a tree of their own if you like (that might have other consequences). Lastly you could traverse the root and check each node to see if it is in your list.

But is there any way to determine whether a given XML element is part of the current user selection? This information shows up as an underlined element in the Structure window, but I can't seem to find a parallel property in the InDesign object model.

I do not believe you have access to what is selected in the Structure pane from the scripting DOM. Sorry.

You can, of course, find the associatedXMLElement of a selected object on the page, though.

Why do you want to do this?

Related to this, but a more general question, is whether the start element for the XMLRules processor can be something other than the root element? All of the published examples start at the root, but is it possible to pass an arbitrary element as the root for use by the processor?

Of course! But why are you asking rather than testing? It should be the work of a moment to test, and then you'd know for certain!

Andreas Jansson
Inspiring
June 27, 2011

Hi John,

You often react on words, being used improperly. In order for us (me) to learn, please define your view on the subject better and explain the errors, such as the difference between traversing and iterating.

Can not iteration be recursive, and thus a normal way to traverse a tree (i.e. the exact same thing as traversing)?

Thanks,

Andreas

vze26m98
vze26m98Author
Known Participant
June 27, 2011

Well, John's correct. Iteration has the general sense of "doing things one after the other," but computer science makes a distinction between between iteration and recursion, or perhaps imperative and declarative programming styles. Tree traversal is the appropriate word here, which typically means a recursive approach, but "iterative traversal" is also possible.

The Wikipedia can provide quick answers to the above.

Best, Charles