Chapter 1. FAQs

Table of Contents

How do I declare a namespace in my ruleset?
How do I write modular rulesets?
How can I batch process XML files?
Can I use named character entities in my ruleset?
How do I emit a normalized ruleset?
How to re-map external entities?

How do I declare a namespace in my ruleset?

Before an XPath expression containing a namespace prefix can be evaluated, the namespace must be declared in the ruleset, using silcn:namespace-declaration (XMLProbe reports a fatal error for unresolvable namespace prefixes). This simply maps the prefix to an appropriate URI:

<silcn:namespace-declaration>
  <silcn:uri>http://www.w3.org/1999/xhtml</silcn:uri>
  <silcn:prefix>xhtml</silcn:prefix>
</silcn:namespace-declaration>

An XPath expression can then be constructed to address elements and attributes in this namespace:

<silcn:set-criterion>
  <silcn:expression>//xhtml:p</silcn:expression>
  <probe:message>found a <probe:eval>name()</probe:eval>!</probe:message>
</silcn:set-criterion>

Important

The default namespace

  • In XPath expressions, there is no such thing as a 'default namespace' for elements and attributes. The empty prefix always resolves to the empty namespace URI (see XPath 1.0 for details). Declaring the empty prefix for a namespace therefore has no effect:

    <!--WRONG-->
    
    <silcn:namespace-declaration>
      <silcn:uri>http://foo.com</silcn:uri>
      <silcn:prefix></silcn:prefix>
    </silcn:namespace-declaration>

Avoiding namespace prefixes

  • It's possible to write XPath expressions for documents which utilize namespaces that avoid namespace-specific syntax. For instance, local-name() and namespace-uri() used in conjunction can avoid namespace prefixes altogether:

    <!--avoids namespace prefixes-->
    
    <silcn:expression>//*[ local-name(.) = 'p' and namespace-uri(.) = 'http://www.w3.org/1999/xhtml' ]</silcn:expression>

    This expression locates all p elements in the XHTML namespace without recourse to namespace prefixes.

    BUT note that any undeclared namespace prefixes will be reported as null:... by XMLProbe, which may hamper onward processing of the report document.