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

RE: XMLSchema or DTD validation

Expand Messages
  • David Fishburn
    I use xmllint (http://xmlsoft.org/) to do this which I tweaked for the Windows platform (had to double quote and convert slashes). For XML validation, use
    Message 1 of 3 , Sep 9, 2003
      I use xmllint (http://xmlsoft.org/) to do this which I tweaked for the
      Windows platform (had to double quote and convert slashes).

      For XML validation, use :compiler xmllint | :make
      Xmllint can do the schema validation, I never had to do this, but if you
      get it to work, could you send me a snippet of a map that you make.

      Here is my c:\vim\vimfiles\compiler\xmllint.vim
      " Vim compiler file
      " Compiler: xmllint
      " Maintainer: Doug Kearns <djkea2@...>
      " URL:
      " Last Change: Sun Jul 20 2003 1:12:29 PM

      if exists("current_compiler")
      let current_compiler = "xmllint"

      let s:cpo_save = &cpo
      set cpo-=C

      " Original command
      " setlocal makeprg=xmllint\ --valid\ --noout

      " Only filename
      " let makecmd='xmllint --valid --noout' . " " . expand("%:t")
      " Get full path to name and flip backslashes to forward slashes
      let filename = expand("%:p")
      if has('win32')
      let filename = '"'.substitute( expand("%:p"), '\', '/', 'g' ).'"'
      let makecmd='xmllint --valid --noout' . " " . filename
      let &l:makeprg=makecmd

      setlocal errorformat=%E%f:%l:\ error:\ %m,
      \%W%f:%l:\ warning:\ %m,
      \%E%f:%l:\ validity\ error:\ %m,
      \%W%f:%l:\ validity\ warning:\ %m,

      let &cpo = s:cpo_save
      unlet s:cpo_save

      I also created the following:
      " XML filetype plugin file
      " Language: XML files (XSL as well)
      " Maintainer: David Fishburn <fishburn@...>
      " Last Change: Sun Jul 20 2003 8:36:02 AM

      " XML/XSL formatting
      setlocal shiftwidth=2

      " Use the open source tool to veryify XML/XSL
      compiler xmllint

      " Use the open source tool to reformat the document
      " Double quote the filename if on windows
      if has('win32')
      vnoremap <buffer> <Leader>xf :!xmllint --format "-"<CR>
      vnoremap <buffer> <Leader>xf :!xmllint --format -<CR>

      This will allow you to visually select the entire file (ggVG) and format

      Here is the usage for xmllint.exe to see if it will do what you need.
      900 15:30:04 D:\download\OpenSrc\XML>xmllint
      Usage : xmllint [options] XMLfiles ...
      Parse the XML files and output the result of the parsing
      --version : display the version of the XML library used
      --debug : dump a debug tree of the in-memory document
      --shell : run a navigating shell
      --debugent : debug the entities defined in the document
      --copy : used to test the internal copy implementation
      --recover : output what was parsable on broken XML documents
      --noent : substitute entity references by their value
      --noout : don't output the result tree
      --htmlout : output results as HTML
      --nowrap : do not put HTML doc wrapper
      --valid : validate the document in addition to std well-formed
      --postvalid : do a posteriori validation, i.e after parsing
      --dtdvalid URL : do a posteriori validation against a given DTD
      --timing : print some timings
      --output file or -o file: save to a given file
      --repeat : repeat 100 times, for timing or profiling
      --insert : ad-hoc test for valid insertions
      --sgml : use the DocBook SGML parser
      --html : use the HTML parser
      --push : use the push mode of the parser
      --nowarning : do not emit warnings from parser/validator
      --noblanks : drop (ignorable?) blanks spaces
      --format : reformat/reindent the input
      --testIO : test user I/O support
      --encode encoding : output in the given encoding
      --catalogs : use SGML catalogs from $SGML_CATALOG_FILES
      otherwise XML Catalogs starting from
      file:///etc/xml/catalog are activated by default
      --nocatalogs: deactivate all catalogs
      --auto : generate a small doc on the fly
      --xinclude : do XInclude processing
      --loaddtd : fetch external DTD
      --dtdattr : loaddtd + populate the tree with inherited
      --dropdtd : remove the DOCTYPE of the input docs
      --stream : use the streaming interface to process very large
      --chkregister : verify the node registration code
      --relaxng schema : do RelaxNG validation against the schema

      Libxml project home page: http://xmlsoft.org/
      To report bugs or get some help check: http://xmlsoft.org/bugs.html


      -----Original Message-----
      From: Ray Hunter [mailto:bigdog@...]
      Sent: Tuesday, September 09, 2003 12:57 PM
      To: vim@...
      Subject: Re: XMLSchema or DTD validation

      > Is there a way to validate an XML doc against a schema or DTD? Or
      > maybe to teach VI which tags and attributes are possible in a certain
      > place of a document being edited?

      You can set up xerces to be a compiler for .xml files and do the

      I am not up to par on setting the compiler options for this but am
      almost certain it could be done.

      Here is the link: http://xml.apache.org/xerces2-j/index.html

      I like using the java version, never tried the c++ version.

    Your message has been successfully submitted and would be delivered to recipients shortly.