Skip to content

Commit

Permalink
Rewrite flycheck-parse-xml-region (use xml-parse-region if libxml fails)
Browse files Browse the repository at this point in the history
Closes GH-1298, GH-1330.
  • Loading branch information
cpitclaudel committed Oct 25, 2017
1 parent 66b0e49 commit 92f5654
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions flycheck.el
Expand Up @@ -5521,19 +5521,25 @@ function `buffer-file-name'."
(defun flycheck-parse-xml-region (beg end)
"Parse the xml region between BEG and END.

Wrapper around `xml-parse-region' which transforms the return
value of this function into one compatible to
Try parsing with libxml first; if that fails, revert to
`xml-parse-region'. Failures can be caused by slightly incorrect
XML (see URL `https://github.com/flycheck/flycheck/issues/1298'),
or on Windows by a missing libxml DLL with a libxml-enabled Emacs
build (see URL `https://github.com/flycheck/flycheck/issues/1330').

The output of `xml-parse-region' is made compatible with that of
`libxml-parse-xml-region' by simply returning the first element
from the node list."
(car (xml-parse-region beg end)))
of the node list."
;; FIXME use `libxml-available-p' when it gets implemented.
(or (and (fboundp 'libxml-parse-xml-region)
(libxml-parse-xml-region beg end))
(ignore-errors (car (xml-parse-region beg end)))))

(defvar flycheck-xml-parser
(if (fboundp 'libxml-parse-xml-region)
'libxml-parse-xml-region 'flycheck-parse-xml-region)
"Parse an xml string from a region.
(defvar flycheck-xml-parser 'flycheck-parse-xml-region
"Function used to parse an xml string from a region.

Use libxml if Emacs is built with libxml support. Otherwise fall
back to `xml-parse-region', via `flycheck-parse-xml-region'.")
The default uses libxml if available, and falls back to
`xml-parse-region' otherwise.")

(defun flycheck-parse-xml-string (xml)
"Parse an XML string.
Expand Down

0 comments on commit 92f5654

Please sign in to comment.