;; 2023-06-25 ;; each tag must have a opening tag and a closing tag. ;; except if the tag ends in /> then it is a self closing. in xml. ;; tag sequence occure in 2 ways ;; one is nested, like so ;; ( ( 3c9de ( 530 ) toh ) ) ;; the other situation is sequential ;; ( ) () () ;; algorithm outline ;; one way, is to grab whole file, split into a list by angle braket, then process each item. ;; second way, is open the file, then move cursor to beginning, then, search for the next occurance of angle bracket. then, grab it, it is a tag, may be opening tag or closing, push it onto stack. ;; continue. (defun xah-validate-xml-buffer () "validator for xml, check well-formedness version 2023-06-25" (interactive) (let (xp1 xp2 xtag (xstack '())) ;; get current pos, find next angle brack pos, grab text in between, that's one tag, push it to stack (goto-char (point-min)) (while (re-search-forward "[<>]" nil t) (progn (if (eq (char-before) ?<) (setq xp1 (1- (point))) (error "error found at position %s" (point))) (re-search-forward "[<>]" nil t) (if (eq (char-before) ?>) (setq xp2 (point)) (error "error found at position %s" (point))) (setq xtag (buffer-substring-no-properties xp1 xp2)) (if (xah-is-selfclosing xtag) nil (push xtag xstack))) ;; xah-html--opening-tag-p ;; some code to check stack ;; ) (print xstack))) (defun xah-is-selfclosing (Tagstring) "return t if Tagstring ends in />" (if (string-equal "/>" (substring Tagstring -2)) t nil ))