=== modified file 'lisp/xml.el' --- lisp/xml.el 2012-07-04 16:14:05 +0000 +++ lisp/xml.el 2012-07-25 20:54:52 +0000 @@ -126,7 +126,10 @@ would be represented by - '(\"\" . \"foo\")." + '(\"\" . \"foo\"). + +If you'd just like a plain symbol instead, use 'symbol-qnames in +the PARSE-NS argument." (car node)) @@ -313,7 +316,22 @@ "Parse the well-formed XML file FILE. Return the top node with all its children. If PARSE-DTD is non-nil, the DTD is parsed rather than skipped. -If PARSE-NS is non-nil, then QNAMES are expanded." + +If PARSE-NS is non-nil, then QNAMES are expanded. By default, +the variable `xml-default-ns' is the mapping from namespaces to +URIs, and expanded names will be returned as a cons + + (\"namespace:\" . \"foo\"). + +If PARSE-NS is an alist, it will be used as the mapping from +namespace to URIs instead. + +If it is the symbol 'symbol-qnames, expanded names will be +returned as a plain symbol 'namespace:foo instead of a cons. + +Both features can be combined by providing a cons cell + + (symbol-qnames . ALIST)." (with-temp-buffer (insert-file-contents file) (xml--parse-buffer parse-dtd parse-ns))) @@ -329,7 +347,21 @@ If BUFFER is nil, it defaults to the current buffer. If PARSE-DTD is non-nil, parse the DTD and return it as the first element of the list. -If PARSE-NS is non-nil, expand QNAMES." +If PARSE-NS is non-nil, then QNAMES are expanded. By default, +the variable `xml-default-ns' is the mapping from namespaces to +URIs, and expanded names will be returned as a cons + + (\"namespace:\" . \"foo\"). + +If PARSE-NS is an alist, it will be used as the mapping from +namespace to URIs instead. + +If it is the symbol 'symbol-qnames, expanded names will be +returned as a plain symbol 'namespace:foo instead of a cons. + +Both features can be combined by providing a cons cell + + (symbol-qnames . ALIST)." ;; Use fixed syntax table to ensure regexp char classes and syntax ;; specs DTRT. (unless buffer @@ -377,7 +409,7 @@ (cons dtd (nreverse xml)) (nreverse xml))))) -(defun xml-maybe-do-ns (name default xml-ns) +(defun xml-maybe-do-ns (name default xml-ns symbol-qnames) "Perform any namespace expansion. NAME is the name to perform the expansion on. DEFAULT is the default namespace. XML-NS is a cons of namespace @@ -386,7 +418,10 @@ During namespace-aware parsing, any name without a namespace is put into the namespace identified by DEFAULT. nil is used to -specify that the name shouldn't be given a namespace." +specify that the name shouldn't be given a namespace. +Expanded names will by default be returned as a cons. If you +would like to get plain symbols, set SYMBOL-QNAMES to a non-nil +value." (if (consp xml-ns) (let* ((nsp (string-match ":" name)) (lname (if nsp (substring name (match-end 0)) name)) @@ -397,15 +432,18 @@ (ns (or (cdr (assoc (if special "xmlns" prefix) xml-ns)) ""))) - (cons ns (if special "" lname))) + (if (and symbol-qnames + (not (string= prefix "xmlns"))) + (intern (concat ns lname)) + (cons ns (if special "" lname)))) (intern name))) (defun xml-parse-tag (&optional parse-dtd parse-ns) "Parse the tag at point. If PARSE-DTD is non-nil, the DTD of the document, if any, is parsed and returned as the first element in the list. -If PARSE-NS is non-nil, expand QNAMES; if the value of PARSE-NS -is a list, use it as an alist mapping namespaces to URIs. +If PARSE-NS is non-nil, expand QNAMES; for further details, see +`xml-parse-region'. Return one of: - a list : the matching node @@ -425,15 +463,23 @@ (defun xml-parse-tag-1 (&optional parse-dtd parse-ns) "Like `xml-parse-tag', but possibly modify the buffer while working." - (let ((xml-validating-parser (or parse-dtd xml-validating-parser)) - (xml-ns (cond ((consp parse-ns) parse-ns) - (parse-ns xml-default-ns)))) + (let* ((xml-validating-parser (or parse-dtd xml-validating-parser)) + (symbol-qnames + (when (or (eq parse-ns 'symbol-qnames) + (eq (car-safe parse-ns) 'symbol-qnames)) + 'symbol-qnames)) + (xml-ns + (cond ((symbolp (car-safe parse-ns)) + (or (cdr-safe parse-ns) + xml-default-ns)) + ((consp parse-ns) parse-ns) + (parse-ns xml-default-ns)))) (cond ;; Processing instructions, like . ((looking-at "<\\?") (search-forward "?>") (skip-syntax-forward " ") - (xml-parse-tag-1 parse-dtd xml-ns)) + (xml-parse-tag-1 parse-dtd (cons symbol-qnames xml-ns))) ;; Character data (CDATA) sections, in which no tag should be interpreted ((looking-at "") @@ -456,7 +502,7 @@ (skip-syntax-forward " ") (unless (eobp) (let ((xml-sub-parser t)) - (xml-parse-tag-1 parse-dtd xml-ns)))) + (xml-parse-tag-1 parse-dtd (cons symbol-qnames xml-ns))))) ;; end tag ((looking-at "") @@ -502,7 +549,7 @@ node-name)) ;; Read a sub-element and push it onto CHILDREN. ((= (char-after) ?<) - (let ((tag (xml-parse-tag-1 nil xml-ns))) + (let ((tag (xml-parse-tag-1 nil (cons symbol-qnames xml-ns)))) (when tag (push tag children)))) ;; Read some character data. @@ -585,7 +632,7 @@ (goto-char end-marker) (buffer-substring start (point))))) -(defun xml-parse-attlist (&optional xml-ns) +(defun xml-parse-attlist (&optional xml-ns symbol-qnames) "Return the attribute-list after point. Leave point at the first non-blank character after the tag." (let ((attlist ()) @@ -594,7 +641,8 @@ (while (looking-at (eval-when-compile (concat "\\(" xml-name-re "\\)\\s-*=\\s-*"))) (setq end-pos (match-end 0)) - (setq name (xml-maybe-do-ns (match-string-no-properties 1) nil xml-ns)) + (setq name (xml-maybe-do-ns (match-string-no-properties 1) + nil xml-ns symbol-qnames)) (goto-char end-pos) ;; See also: http://www.w3.org/TR/2000/REC-xml-20001006#AVNormalize