]> code.delx.au - gnu-emacs/blobdiff - lisp/xml.el
There's no reason not to compile version.el
[gnu-emacs] / lisp / xml.el
index a33d44dc6cb24d978df2c3cdbe0b4cedbbde43f1..cb56f023af060a3c43856e4ad35bbd1efca88ad1 100644 (file)
@@ -1,7 +1,6 @@
 ;;; xml.el --- XML parser
 
-;; Copyright (C) 2000, 2001, 2002, 2003, 2004,
-;;   2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+;; Copyright (C) 2000-2012 Free Software Foundation, Inc.
 
 ;; Author: Emmanuel Briot  <briot@gnat.com>
 ;; Maintainer: Mark A. Hershberger <mah@everybody.org>
@@ -189,7 +188,7 @@ If PARSE-NS is non-nil, then QNAMES are expanded."
        (name-chars  (concat "-[:digit:]." start-chars))
        ;;[3]           S          ::=          (#x20 | #x9 | #xD | #xA)+
        (whitespace  "[ \t\n\r]"))
-  ;;[4] NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] 
+  ;;[4] NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6]
   ;;                      | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF]
   ;;                      | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF]
   ;;                      | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
@@ -227,7 +226,7 @@ If PARSE-NS is non-nil, then QNAMES are expanded."
   (defvar xml-notation-type-re (concat "\\(?:NOTATION" whitespace "(" whitespace "*" xml-name-re
                                       "\\(?:" whitespace "*|" whitespace "*" xml-name-re "\\)*" whitespace "*)\\)"))
   ;;[59]       Enumeration        ::=          '(' S? Nmtoken (S? '|' S? Nmtoken)* S? ')'      [VC: Enumeration] [VC: No Duplicate Tokens]
-  (defvar xml-enumeration-re (concat "\\(?:(" whitespace "*" xml-nmtoken-re 
+  (defvar xml-enumeration-re (concat "\\(?:(" whitespace "*" xml-nmtoken-re
                                     "\\(?:" whitespace "*|" whitespace "*" xml-nmtoken-re "\\)*"
                                     whitespace ")\\)"))
   ;;[57]       EnumeratedType     ::=          NotationType | Enumeration
@@ -248,7 +247,7 @@ If PARSE-NS is non-nil, then QNAMES are expanded."
                                         xml-pe-reference-re "\\|" xml-reference-re "\\)*'\\)")))
 ;;[75] ExternalID ::= 'SYSTEM' S SystemLiteral
 ;;                 | 'PUBLIC' S PubidLiteral S SystemLiteral
-;;[76] NDataDecl ::=           S 'NDATA' S 
+;;[76] NDataDecl ::=           S 'NDATA' S
 ;;[73] EntityDef  ::= EntityValue| (ExternalID NDataDecl?)
 ;;[71] GEDecl     ::= '<!ENTITY' S Name S EntityDef S? '>'
 ;;[74] PEDef      ::= EntityValue | ExternalID
@@ -324,7 +323,8 @@ If PARSE-NS is non-nil, then QNAMES are expanded."
                  (cond
                   ((null result)
                    ;; Not looking at an xml start tag.
-                   (forward-char 1))
+                   (unless (eobp)
+                     (forward-char 1)))
                   ((and xml (not xml-sub-parser))
                    ;; Translation of rule [1] of XML specifications
                    (error "XML: (Not Well-Formed) Only one root tag allowed"))
@@ -422,7 +422,9 @@ Returns one of:
      ;;  skip comments
      ((looking-at "<!--")
       (search-forward "-->")
-      nil)
+      (skip-syntax-forward " ")
+      (unless (eobp)
+       (xml-parse-tag parse-dtd xml-ns)))
      ;;  end tag
      ((looking-at "</")
       '())
@@ -434,7 +436,7 @@ Returns one of:
       (let* ((node-name (match-string-no-properties 1))
             ;; Parse the attribute list.
             (attrs (xml-parse-attlist xml-ns))
-            children pos)
+            children)
 
        ;; add the xmlns:* attrs to our cache
        (when (consp xml-ns)
@@ -537,12 +539,11 @@ Leave point at the first non-blank character after the tag."
 
       ;; Multiple whitespace characters should be replaced with a single one
       ;; in the attributes
-      (let ((string (match-string-no-properties 1))
-           (pos 0))
+      (let ((string (match-string-no-properties 1)))
        (replace-regexp-in-string "\\s-\\{2,\\}" " " string)
        (let ((expansion (xml-substitute-special string)))
          (unless (stringp expansion)
-                                       ; We say this is the constraint.  It is acctually that
+                                       ; We say this is the constraint.  It is actually that neither
                                        ; external entities nor "<" can be in an attribute value.
            (error "XML: (Not Well-Formed) Entities in attributes cannot expand into elements"))
          (push (cons name expansion) attlist)))
@@ -635,7 +636,7 @@ This follows the rule [28] in the XML specifications."
             ((string-match "^%[^;]+;[ \t\n\r]*$" type) ;; substitution
              nil)
             (t
-             (if xml-validating-parser 
+             (if xml-validating-parser
                  (error "XML: (Validity) Invalid element type in the DTD"))))
 
            ;;  rule [45]: the element declaration must be unique
@@ -667,7 +668,7 @@ This follows the rule [28] in the XML specifications."
              (goto-char (match-end 0))
              (setq xml-entity-alist
                    (append xml-entity-alist
-                           (list (cons name 
+                           (list (cons name
                                        (with-temp-buffer
                                          (insert value)
                                          (goto-char (point-min))
@@ -758,7 +759,7 @@ This follows the rule [28] in the XML specifications."
 ;;*******************************************************************
 
 (defun xml-substitute-special (string)
-  "Return STRING, after subsituting entity references."
+  "Return STRING, after substituting entity references."
   ;; This originally made repeated passes through the string from the
   ;; beginning, which isn't correct, since then either "&amp;amp;" or
   ;; "&#38;amp;" won't DTRT.
@@ -770,7 +771,7 @@ This follows the rule [28] in the XML specifications."
       (let* ((this-part (match-string-no-properties 1 string))
             (prev-part (substring string point (match-beginning 0)))
             (entity (assoc this-part xml-entity-alist))
-            (expansion 
+            (expansion
              (cond ((string-match "#\\([0-9]+\\)" this-part)
                     (let ((c (decode-char
                               'ucs