in reply to Creating context-specific handlers in XML::Twig

First a generic comment on questions: if you want a somewhat complete solution, you need to give _all_ of the relevant data. If I can write a test case from the information you give, then I can start really working on it. If the test case is already written, than that's even better BTW.

Here you mention that some of the data is missing, so I can hopefully give you "a nudge in the right direction", but no more, and I can't even really understand properly what you want to do if I know that I am missing some pieces of the puzzle.

With that out of the way... let see if I can give you what you asked for ;--)

The expression that trigger handlers are that: expressions. They are not limited to just tag names. Look for twig_handlers in the docs (badly formatted version here). So you can certainly use an expression like UML:Attribute/UML:ModelElement.taggedValue/UML:TaggedValue[@tag="ea_guid"] to trigger a handler just when you need it.

In order to ignore the rest of the UML:TaggedValue elements, you can just not do anything with them, or if you want to actively prevent them from being included in the document tree, use the ignore method, but that's probably not worth the effort.

Does that help?

Replies are listed 'Best First'.
Re^2: Creating context-specific handlers in XML::Twig
by bobf (Monsignor) on Nov 11, 2007 at 05:35 UTC

    Thanks for the suggestions. I know the OP was a little sketchy on detail, but that was intentional. I hoped that the snippets of XML and code would give readers enough of a feel for how I was approaching the problem to understand my train(wreck) of thought, and to the extent that I did not achieve that I apologize.

    At this stage I am more interested in understanding the pros and cons to different approaches to the problem than the implementation details. That said, I would welcome any example code that you or any others are willing to provide, and to that end I am working on creating example input, output, and test code. I will update this thread when it is ready.

    Re: twig handlers being expressions rather than simple tag names. Thank you for pointing that out - I never realized that there was so much flexibility. I will definitely experiment with it.

    In summary, thanks for the reply. Between your comments and the example that GrandFather provided, I am tweaking my code to see if I can clean up the flow a bit. I will post an example soon.