Loading ...
Sorry, an error occurred while loading the content.

Hook for using PI with nXML mode

Expand Messages
  • Tony Graham
    The PI [1] is being jointly developed by W3C and ISO/IEC JTC1/SC34 as a way to associate schemas with XML documents. Here s a simple hook
    Message 1 of 1 , Mar 29, 2011
    • 0 Attachment
      The <?xml-model?> PI [1] is being jointly developed by W3C and ISO/IEC
      JTC1/SC34 as a way to associate schemas with XML documents.

      Here's a simple hook function for using the PI when it refers to a RNC
      file on the local file system.

      Regards,


      Tony Graham
      Mentea.

      [1] http://www.w3.org/TR/xml-model/

      --------------------------------------------------
      (defun use-xml-model ()
      "Hook function for `nxml-mode' to use <?xml-model?> PI for locating a
      RNC schema."
      (interactive)
      (save-excursion
      (goto-char (point-min))
      (if (search-forward "<?xml-model " nil t)
      (progn
      (goto-char (match-end 0))
      (let* ((pi-end (save-excursion
      (search-forward "?>" nil t)
      (match-beginning 0)))
      (filename (save-excursion
      (re-search-forward "href=\"\\([^\"]+\.rnc\\)\""
      pi-end t)
      (match-string 1))))
      ;; (message "pi-end: %d; filename: %s; compact: %s"
      ;; pi-end filename compact)
      (if (and filename (file-readable-p filename))
      (rng-set-schema-file filename)))))))

      (add-hook 'nxml-mode-hook
      'use-xml-model)
      --------------------------------------
    Your message has been successfully submitted and would be delivered to recipients shortly.