protected function xpath($query, $args = null)
    {
        $xpath = new DOMXPath($this->document);
        // Preregister namespaces.
        $xpath->registerNamespace('wsdl', self::WSDL_NS);
        $xpath->registerNamespace('s', self::SCHEMA_NS);

        // Arguments containing ' and " needs escaping.
        // Inspired by https://gist.github.com/jaywilliams/2883026/#comment-813400.
        $args = func_get_args();
        array_shift($args);
        foreach ($args as &$arg) {
            if (strpos($arg, "'") === false) {
                $arg = sprintf("'%s'", $arg);
            } elseif (strpos($arg, '"') === false) {
                $arg = sprintf('"%s"', $arg);
            } else {
                $arg = sprintf("concat('%s')", str_replace("'", "',\"'\",'", $arg));
            }
        }

        // Generate XPath query with esacped arguments.
        $query = call_user_func_array('sprintf', array_merge(array($query), $args));

        return $xpath->query($query, $this->element);
    }