Invenzzia » Resources / Articles / Managing XML in OPT / Final information

8. Final information

In the example codes we could have seen many different namespaces, with the primary one opt:. What if we use a tag that is not recognizable by OPT? To answer for that question, we must learn how OPT processes the XML namespaces. They are divided in two groups:

  • User namespaces - we do not check what they are, but just rewrite them to the output.
  • OPT namespaces - they contain OPT control stuff and we must process them.

The namespaces that belong to the first group, are displayed in the output code immediately. The second group is processed by OPT and their tags do not appear in the output. If OPT encounters an tag in an OPT namespace and is not able to recognize it (i.e. something like opt:foo), it ignores it together with the content. It makes finding mistakes a bit harder, but is necessary, because some instructions make a heavy use of such anonymous tags. What is more, the programmer may give them an extra meaning by creating a new instruction or component.

The OPT namespaces must be registered in the main library object. By default, there are three of them: opt, parse and str. To register a new one, we use the register() method:

$tpl = new Opt_Class;
// ...
$tpl->register(Opt_Class::OPT_NAMESPACE, 'foo');
// ...
$tpl->setup();

Now OPT treats the foo namespace as the internal namespace and we can add our own instructions, components and blocks to it.