Using XML Schema for code autocomplete in editor?

Answered

Hi,

it would be great if I could somehow have an autocomplete function for my XML tags, attributes etc. using the schema in XSD file. In XML file I am editing (E.g. test.myxml), I can not have anything else but the elements defined in XSD file. So I can just have the following and absolutely nothing else (no header) E.g.:

<root>
  <panel id="panel1">
  <field id="field1">Test Field</field>
</panel>
</root>

I've tried defining my External Schema in Languages & Frameworks -> Schemas and DTDs. Gave it some URI, linked it with the right XSD file.

Then in Languages & Frameworks -> Schemas and DTDs -> Default XML Schemas I selected Other doctype and Copy/Pasted the URI string from previous step.

*.myxml file extension is properly defined as an XML File Type.

However, that did not work. Is there any way to do it in IntelliJ IDEA at all. Am I doing something wrong?

Thanks!

3 comments
Comment actions Permalink

This should work, see https://www.jetbrains.com/help/idea/2016.1/validating-web-content-files.html for details.

Please share a sample project with the XML and XSD if it doesn't work for you.

0
Comment actions Permalink

Thanks, I saw that already. I actually narrowed it down. So "http://something.com/schema" is the schema I registered in IntelliJ.

So autocomplete actually works like this:

<root xmlns="http://something.com/schema">
  <panel id="panel1">
  <field id="field1">Test Field</field>
</panel>
</root>

However, I would like to have just this:

<root>
  <panel id="panel1">
  <field id="field1">Test Field</field>
</panel>
</root>

and to have the autocomplete work anyway. I was hoping to solve it with Default XML Schemas but it doesn't work, even though my file extension is registered in IntelliJ as XML file type.

Is there perhaps an option that says For files with THIS extension use THAT XML Schema? Where we can specify both THIS extension and THAT XML Schema.

 

 

 

0
Comment actions Permalink

Hello,

You just need to put the xsd url in schemaLocation attribute in your xml. The editor will detect the xsd and start validation and autocomplete.

 

Reference:

https://www.jetbrains.com/help/idea/referencing-xml-schemas-and-dtds.html

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

0

Please sign in to leave a comment.