开发者

Using XML Schema for code autocomplete in my XML editor

I have XSD file (for example) http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd and I would like to use it for adding code autocomplete in my xml editor (I prefer Eclips开发者_运维百科e but any other free editor would be O.K.).

Is it possible? And if Yes, how can I do it?


I had a similar problem but did not find a solution here so I posted a similar question. The answer led me to the Eclipse XML Editors and Tools plugin in Eclipse which supports autocomplete based on XML Schema.

Once the XML document is associated with the relevant XSD file, autocomplete should kick in automatically.

p.s. Considering the date of your question, you probably already found a suitable solution. However I thought I'd leave this answer anyway as a heads up to future visitors. HTH.


Using XML Schema for code autocomplete is supported in Visual Studio more details here.

Alternative XML editor is: Microsoft XML Notepad 2007 (personally I found this editor to be very unfriendly, is very visual but editing files is not very productive)


I think you can do it by defining an XML namespace with your XML Schema Definition. Then when you start a tag with that namespace you should get suggestions based on the types of elements that can be used in that situation, according to the XML Schema Definition.


In Visual Studio 2015 (and most likely earlier versions as well) just go to the Properties tab of the XML file in the solution and specify the path to the xsd in the Schemas attribute.

I haven't spent much time on it, but looks like VS doesn't save the mapping in the csproj file, so the setting won't go in the version control, but if that's not something important for you, it's a quick and easy way to solve the problem.


xsi:schemaLocation

It is supported by default in Eclipse. You just need to add XSI and schemaLocation as the following example.

<Resource xmlns="http://xml.metamug.net/resource/1.0"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://xml.metamug.net/resource/1.0 http://xml.metamug.net/schema/resource.xsd">
</Resource>

As you can see above, you have need 3 attributes. The autocomplete works because of the valid xsd hosted on a public url and provided in the xsi:schemaLocation attribute

Note that all Editors don't support this by default, but Eclipse and Netbeans I know do.

Reference: https://metamug.com/article/auto-complete-xml-editor-with-xsd-and-validations.php

Using XML Schema for code autocomplete in my XML editor

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜