6

I use VIM as my text editor and I edit a lot of XML and WSDL files.

WSDL files have an XSD section. Is there some VIM plugin I can use to traverse the XSD types? i.e., if I have the following line and the caret is where the '|' sign is:

<xsd:element minOccurs="0" name="FooName" type="Magic|FooType"/>

and I press Ctrl+Alt+Foo (or some other magic combo) it will get me to the definition of MagicFooType, i.e.:

<xsd:complexType name="MagicFooType">

I couldn't find how to use ctags for this and all the other plugins that I could find are for imperative languages (i.e. Java). Is there some plugin/script to do the job?

1

3 Answers 3

3

This is relatively easy to achieve using ctags. I use Vim exclusively for XSD editing and in combination with exuberant ctags (http://ctags.sourceforge.net/) this works very well for me.

Because exuberant ctags doesn't support XSD out of the box you need to generate a custom language definition.

I use the file below as .ctags in my XSD project. After running the ctags command in the project root, I can use standard VIM tag navigation (Ctrl-[ for follow and Ctrl-O for back) for jumping to definitions.

To get vim to pick up tags files in parent directories I use the following snippet in my .vimrc

set tags=./tags;

Put this in .ctags in your project root.

--langdef=XSD
--langmap=XSD:+.xsd
--langmap=XSD:+.wsdl
--regex-XSD=/element name="([a-zA-Z0-9_]+:){0,1}([a-zA-Z0 -9_]+)"/\2/d,definition/
--regex-XSD=/Type [a-zA-Z0-9="]*[ ]{0,1}name="([a-z_]+:){0,1}([a-zA-Z0-9_]+)"/\2/d,definition/
--exclude=.git
--recurse=yes
2

I have been watching this thread for a bit and wondering this myself as I am a VIM user and work with a lot of very large XML files and associated XSD's, XSLT's and XQuery files, all of which could benefit from this sort of thing, as I am sure you can imagine.

After some research this can be done with ctags, but there is nothing out there at the moment which will create the ctags file for it. Essentially a ctag looks like this:

{tagname}<tab>{tagfile}<tab>{tagaddress}

Because the tagaddress is an ex mode command it can take you anywhere in a particular file to land right on the definition.

Basically all we would need to do is create a script which would run through the WSDL (or XSD, or whatever) and, knowing the location of the tag and file, create the appropriate lines in a ctags file to map all of the definitions. Sounds like a fun and useful little project.

Sorry that this isn't exactly a complete answer, but it is possible to do with ctags and will give you the robustness you and looking for.

3
  • Sadly it seems the most practical way. Well, who knows, maybe this summer between another two projects :) If I'll take on this in 1 month time, would you like to collaborate?
    – maayank
    Commented Jun 19, 2010 at 8:58
  • I would be glad to yes. In fact I have already discussed this with a few of my coworkers and we all think this would be a good idea. Feel free to contact me offline and we might be able to discuss collaboration ideas.
    – Tim C
    Commented Jun 20, 2010 at 23:10
  • I'm unable to see your email address and I can't find any other method of personal communication on SO, so please send me an email to [email protected] (or leave it here, whatever suits you :)
    – maayank
    Commented Jun 25, 2010 at 4:38
2

gd ("go to declaration") is not aware of the XML format but might do the job in this case, assuming the XSD section is at the top of the WSDL.

1
  • Thanks, a bit better than manually searching the type's name, but as you said, it's not aware of xml/xsd and awkward to use on large files.
    – maayank
    Commented Jun 15, 2010 at 16:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.