Using XML Schema for code autocomplete in my XML editor

前端 未结 5 1635
猫巷女王i
猫巷女王i 2021-01-12 03:22

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 Eclipse bu

相关标签:
5条回答
  • 2021-01-12 03:48

    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.

    0 讨论(0)
  • 2021-01-12 03:54

    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)

    0 讨论(0)
  • 2021-01-12 04:05

    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.

    0 讨论(0)
  • 2021-01-12 04:09

    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

    Metamug Autocomplete XSD Validation

    0 讨论(0)
  • 2021-01-12 04:11

    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.

    0 讨论(0)
提交回复
热议问题