How to associate custom XML schema with XML editor? [message #230533] |
Tue, 21 April 2009 14:14  |
Eclipse User |
|
|
|
I am trying to add content assist and validation to the "stock" XML editor
in a standalone product that repackages the Eclipse 3.3.2 platform and
adds our own plugins. I have:
A) extended org.eclipse.core.contenttype.contentTypes with my own
content-type specifying a base type of org.eclipse.core.runtime.xml and a
org.eclipse.core.runtime.content.XMLRootElementContentDescri ber:myRootElement
describer.
B) extended org.eclipse.wst.xml.core.catalogContributions with my own
catalogContribution pointing to my .xsd file.
However, I don't see 1) how to associate the editor with my .xsd for
content assist (I thought this was done automatically by B); or 2) how to
enable "Validate" on the context menu in the Navigator.
I saw in Nitin's EclipseCon presentation that "Its common to define your
own contentType, say for a specialized form of XML, based on some specific
DTD, and then associate it with your editor," but I can't find any
documentation explaining exactly how to do this.
Any help or direction would be appreciated.
-Dan Hoyt
Senior Systems Architect, TSC
|
|
|
|
|
|
|
Re: How to associate custom XML schema with XML editor? [message #230668 is a reply to message #230660] |
Thu, 23 April 2009 19:32   |
Eclipse User |
|
|
|
Originally posted by: dcarver.starstandard.org
Content Assistance for your Editor probably needs to have a
StructuredSourceViewerConfiguration enabled for it. Here is an example
from the XSLT editor:
<extension point="org.eclipse.wst.sse.ui.editorConfiguration">
<sourceViewerConfiguration
class=" org.eclipse.wst.xsl.ui.internal.StructuredTextViewerConfigur ationXSL "
target="org.eclipse.wst.xml.core.xslsource">
</sourceViewerConfiguration>
</extension>
You'll want to setup the target for your particular content id. You
can use the same StructuredTextViewrConfigurationXML if all you want is
the base support as is provided by the XML editor. So in your case the
target id is: com.mycomany.myproduct.myXML
The question I have in regards to your Schema is, what happens if you
load up using the default XML editor. Do you get the content assistance
that you expect. Your Schema looks fine, and the way you are
contributing to it looks alright.
Dave
Dan Hoyt wrote:
> Sorry for the omission. I was really just trying to understand the
> conceptual answer, but here's my specifics if it will help. Note that
> the URL listed in the namespace will not currently resolve on the web,
> but my understanding is that Eclipse uses the local copy first, so that
> shouldn't be a problem, right?
>
> What does work:
> 1) When I right-click an XML file, I get a new "My XML Editor" entry.
> 2) When I open an XML file that has a "myRoot" root element (*):
> A) The default editor that opens has my "my-xml.gif" icon.
> B) A custom view I developed recognizes that my custom content was
> loaded.
> 3) My schema shows up in "Preferences...|Web and XML|XML Catalog" under
> the "Plugin Specified Entries".
>
> (*) For example:
> <?xml version="1.0" encoding="UTF-8"?>
> <myRoot>
> </myRoot>
>
> What does NOT work:
> 1) When I use the "New|Other...|XML|XML" Wizard and select "Create XML
> file from an XML schema file" and select my schema from the Catalog, the
> "Root element:" selection list is empty.
> 2) Content assist on a file opened as "My XML Editor" gives me the error:
> "Content Assist not available at the current location"
>
> Regards,
> Dan
>
> --------------------------
>
> My plugin's plugin.xml has defined:
>
> <extension
> point="org.eclipse.core.contenttype.contentTypes">
> <content-type
> base-type="org.eclipse.core.runtime.xml"
>
> describer=" org.eclipse.core.runtime.content.XMLRootElementContentDescri ber:myRoot "
>
> file-extensions="xml"
> id="com.mycomany.myproduct.myXML"
> name="My XML"
> priority="normal">
> </content-type>
> </extension>
> <extension
> point="org.eclipse.ui.editors">
> <editor
>
> class=" org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditor Part "
>
> contributorClass=" org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditor ActionBarContributor "
>
> icon="icons/my-xml.gif"
> id="com.mycompany.myproduct.xml"
> name="My XML Editor">
> <contentTypeBinding
> contentTypeId="com.mycomany.myproduct.myXML">
> </contentTypeBinding>
> </editor>
> </extension>
> <extension
> point="org.eclipse.wst.xml.core.catalogContributions">
> <catalogContribution>
> <uri
> name="http://www.mycompany.com/myproduct/2009/XMLSchema"
> uri="schema/myXML.xsd">
> </uri>
> </catalogContribution>
> </extension>
>
> --------------------------
>
> My schema/myXML.xsd looks like:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <schema targetNamespace="http://www.mycompany.com/myproduct/2009/XMLSchema"
> xmlns="http://www.w3.org/2001/XMLSchema"
> xmlns:tns="http://www.mycompany.com/myproduct/2009/XMLSchema">
>
> <element name="myRoot">
> <complexType>
> <sequence>
> <element name="myEntry1" type="tns:EntryType"
> maxOccurs="unbounded" minOccurs="0" />
> <element name="myEntry2" type="tns:EntryType"
> maxOccurs="unbounded" minOccurs="0" />
> ...
> </sequence>
> </complexType>
> </element>
>
> <complexType name="EntryType">
> <choice maxOccurs="unbounded" minOccurs="0">
> <element name="data" type="tns:DoubleValueType" maxOccurs="1"
> minOccurs="1" />
> <element name="data" type="tns:IntegerValueType" maxOccurs="1"
> minOccurs="1" />
> </choice>
> <attribute name="index" type="int" use="optional" />
> <attribute name="size" type="int" use="optional" />
> </complexType>
>
> <complexType name="DoubleValueType">
> <complexContent>
> <extension base="tns:HexValueType">
> <attribute name="value" type="double" use="required" />
> <attribute name="type" use="optional">
> <simpleType>
> <restriction base="string">
> <pattern value=" " />
> </restriction>
> </simpleType>
> </attribute>
> </extension>
> </complexContent>
> </complexType>
>
> <complexType name="IntegerValueType">
> <complexContent>
> <extension base="tns:HexValueType">
> <attribute name="value" type="int" use="required" />
> <attribute name="type" use="required">
> <simpleType>
> <restriction base="string">
> <pattern value="[iI]" />
> </restriction>
> </simpleType>
> </attribute>
> </extension>
> </complexContent>
> </complexType>
>
> ...
>
> </schema>
>
>
|
|
|
Re: How to associate custom XML schema with XML editor? [message #230804 is a reply to message #230668] |
Mon, 27 April 2009 18:54   |
Eclipse User |
|
|
|
David,
I tried configuring the sourceViewerConfiguration, but it didn't appear to
have any effect, even with a namespace attribute on the root element in my
XML file:
<?xml version="1.0" encoding="UTF-8"?>
<myRoot xmlns="http://www.mycompany.com/myproduct/2009/XMLSchema">
...
</myRoot>
This is what I added this to the plugin.xml:
<extension point="org.eclipse.wst.sse.ui.editorConfiguration">
<sourceViewerConfiguration
class="org.eclipse.wst.xml.ui.StructuredTextViewerConfigurationXML "
target="com.mycompany.myproduct.myXML">
</sourceViewerConfiguration>
</extension>
Also, I still don't understand why "Create XML file from an XML schema
file" fails to find the root element.
Regards,
Dan
David Carver wrote:
> Content Assistance for your Editor probably needs to have a
> StructuredSourceViewerConfiguration enabled for it. Here is an example
> from the XSLT editor:
> <extension point="org.eclipse.wst.sse.ui.editorConfiguration">
> <sourceViewerConfiguration
> class=" org.eclipse.wst.xsl.ui.internal.StructuredTextViewerConfigur ationXSL "
> target="org.eclipse.wst.xml.core.xslsource">
> </sourceViewerConfiguration>
> </extension>
> You'll want to setup the target for your particular content id. You
> can use the same StructuredTextViewrConfigurationXML if all you want is
> the base support as is provided by the XML editor. So in your case the
> target id is: com.mycomany.myproduct.myXML
> The question I have in regards to your Schema is, what happens if you
> load up using the default XML editor. Do you get the content assistance
> that you expect. Your Schema looks fine, and the way you are
> contributing to it looks alright.
> Dave
> Dan Hoyt wrote:
>> Sorry for the omission. I was really just trying to understand the
>> conceptual answer, but here's my specifics if it will help. Note that
>> the URL listed in the namespace will not currently resolve on the web,
>> but my understanding is that Eclipse uses the local copy first, so that
>> shouldn't be a problem, right?
>>
>> What does work:
>> 1) When I right-click an XML file, I get a new "My XML Editor" entry.
>> 2) When I open an XML file that has a "myRoot" root element (*):
>> A) The default editor that opens has my "my-xml.gif" icon.
>> B) A custom view I developed recognizes that my custom content was
>> loaded.
>> 3) My schema shows up in "Preferences...|Web and XML|XML Catalog" under
>> the "Plugin Specified Entries".
>>
>> (*) For example:
>> <?xml version="1.0" encoding="UTF-8"?>
>> <myRoot>
>> </myRoot>
>>
>> What does NOT work:
>> 1) When I use the "New|Other...|XML|XML" Wizard and select "Create XML
>> file from an XML schema file" and select my schema from the Catalog, the
>> "Root element:" selection list is empty.
>> 2) Content assist on a file opened as "My XML Editor" gives me the error:
>> "Content Assist not available at the current location"
>>
>> Regards,
>> Dan
>>
>> --------------------------
>>
>> My plugin's plugin.xml has defined:
>>
>> <extension
>> point="org.eclipse.core.contenttype.contentTypes">
>> <content-type
>> base-type="org.eclipse.core.runtime.xml"
>>
>>
describer=" org.eclipse.core.runtime.content.XMLRootElementContentDescri ber:myRoot "
>>
>> file-extensions="xml"
>> id="com.mycompany.myproduct.myXML"
>> name="My XML"
>> priority="normal">
>> </content-type>
>> </extension>
>> <extension
>> point="org.eclipse.ui.editors">
>> <editor
>>
>> class=" org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditor Part "
>>
>>
contributorClass=" org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditor ActionBarContributor "
>>
>> icon="icons/my-xml.gif"
>> id="com.mycompany.myproduct.xml"
>> name="My XML Editor">
>> <contentTypeBinding
>> contentTypeId="com.mycompany.myproduct.myXML">
>> </contentTypeBinding>
>> </editor>
>> </extension>
>> <extension
>> point="org.eclipse.wst.xml.core.catalogContributions">
>> <catalogContribution>
>> <uri
>> name="http://www.mycompany.com/myproduct/2009/XMLSchema"
>> uri="schema/myXML.xsd">
>> </uri>
>> </catalogContribution>
>> </extension>
>>
>> --------------------------
>>
>> My schema/myXML.xsd looks like:
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <schema targetNamespace="http://www.mycompany.com/myproduct/2009/XMLSchema"
>> xmlns="http://www.w3.org/2001/XMLSchema"
>> xmlns:tns="http://www.mycompany.com/myproduct/2009/XMLSchema">
>>
>> <element name="myRoot">
>> <complexType>
>> <sequence>
>> <element name="myEntry1" type="tns:EntryType"
>> maxOccurs="unbounded" minOccurs="0" />
>> <element name="myEntry2" type="tns:EntryType"
>> maxOccurs="unbounded" minOccurs="0" />
>> ...
>> </sequence>
>> </complexType>
>> </element>
>>
>> <complexType name="EntryType">
>> <choice maxOccurs="unbounded" minOccurs="0">
>> <element name="data" type="tns:DoubleValueType" maxOccurs="1"
>> minOccurs="1" />
>> <element name="data" type="tns:IntegerValueType" maxOccurs="1"
>> minOccurs="1" />
>> </choice>
>> <attribute name="index" type="int" use="optional" />
>> <attribute name="size" type="int" use="optional" />
>> </complexType>
>>
>> <complexType name="DoubleValueType">
>> <complexContent>
>> <extension base="tns:HexValueType">
>> <attribute name="value" type="double" use="required" />
>> <attribute name="type" use="optional">
>> <simpleType>
>> <restriction base="string">
>> <pattern value=" " />
>> </restriction>
>> </simpleType>
>> </attribute>
>> </extension>
>> </complexContent>
>> </complexType>
>>
>> <complexType name="IntegerValueType">
>> <complexContent>
>> <extension base="tns:HexValueType">
>> <attribute name="value" type="int" use="required" />
>> <attribute name="type" use="required">
>> <simpleType>
>> <restriction base="string">
>> <pattern value="[iI]" />
>> </restriction>
>> </simpleType>
>> </attribute>
>> </extension>
>> </complexContent>
>> </complexType>
>>
>> ...
>>
>> </schema>
>>
>>
|
|
|
Re: How to associate custom XML schema with XML editor? [message #230810 is a reply to message #230804] |
Mon, 27 April 2009 21:24   |
Eclipse User |
|
|
|
Originally posted by: dcarver.starstandard.org
Does it work with the WTP XML editor.
1. Does it load your grammar.
2. Is content assistance available for your element.
This will help to determine what is happening.
Dave
Dan Hoyt wrote:
> David,
>
> I tried configuring the sourceViewerConfiguration, but it didn't appear
> to have any effect, even with a namespace attribute on the root element
> in my XML file:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <myRoot xmlns="http://www.mycompany.com/myproduct/2009/XMLSchema">
> ..
> </myRoot>
>
> This is what I added this to the plugin.xml:
>
> <extension point="org.eclipse.wst.sse.ui.editorConfiguration">
> <sourceViewerConfiguration
>
> class="org.eclipse.wst.xml.ui.StructuredTextViewerConfigurationXML "
> target="com.mycompany.myproduct.myXML">
> </sourceViewerConfiguration>
> </extension>
>
> Also, I still don't understand why "Create XML file from an XML schema
> file" fails to find the root element.
>
> Regards,
> Dan
>
>
> David Carver wrote:
>
>> Content Assistance for your Editor probably needs to have a
>> StructuredSourceViewerConfiguration enabled for it. Here is an
>> example from the XSLT editor:
>
>> <extension point="org.eclipse.wst.sse.ui.editorConfiguration">
>> <sourceViewerConfiguration
>
>> class=" org.eclipse.wst.xsl.ui.internal.StructuredTextViewerConfigur ationXSL "
>>
>> target="org.eclipse.wst.xml.core.xslsource">
>> </sourceViewerConfiguration>
>> </extension>
>
>> You'll want to setup the target for your particular content id. You
>> can use the same StructuredTextViewrConfigurationXML if all you want
>> is the base support as is provided by the XML editor. So in your case
>> the target id is: com.mycomany.myproduct.myXML
>
>> The question I have in regards to your Schema is, what happens if you
>> load up using the default XML editor. Do you get the content
>> assistance that you expect. Your Schema looks fine, and the way you
>> are contributing to it looks alright.
>
>> Dave
>
>
>> Dan Hoyt wrote:
>>> Sorry for the omission. I was really just trying to understand the
>>> conceptual answer, but here's my specifics if it will help. Note
>>> that the URL listed in the namespace will not currently resolve on
>>> the web, but my understanding is that Eclipse uses the local copy
>>> first, so that shouldn't be a problem, right?
>>>
>>> What does work:
>>> 1) When I right-click an XML file, I get a new "My XML Editor" entry.
>>> 2) When I open an XML file that has a "myRoot" root element (*):
>>> A) The default editor that opens has my "my-xml.gif" icon.
>>> B) A custom view I developed recognizes that my custom content was
>>> loaded.
>>> 3) My schema shows up in "Preferences...|Web and XML|XML Catalog"
>>> under the "Plugin Specified Entries".
>>>
>>> (*) For example:
>>> <?xml version="1.0" encoding="UTF-8"?>
>>> <myRoot>
>>> </myRoot>
>>>
>>> What does NOT work:
>>> 1) When I use the "New|Other...|XML|XML" Wizard and select "Create
>>> XML file from an XML schema file" and select my schema from the
>>> Catalog, the "Root element:" selection list is empty.
>>> 2) Content assist on a file opened as "My XML Editor" gives me the
>>> error:
>>> "Content Assist not available at the current location"
>>>
>>> Regards,
>>> Dan
>>>
>>> --------------------------
>>>
>>> My plugin's plugin.xml has defined:
>>>
>>> <extension
>>> point="org.eclipse.core.contenttype.contentTypes">
>>> <content-type
>>> base-type="org.eclipse.core.runtime.xml"
>>>
> describer=" org.eclipse.core.runtime.content.XMLRootElementContentDescri ber:myRoot "
>
>>>
>>> file-extensions="xml"
>>> id="com.mycompany.myproduct.myXML"
>>> name="My XML"
>>> priority="normal">
>>> </content-type>
>>> </extension>
>>> <extension
>>> point="org.eclipse.ui.editors">
>>> <editor
>>>
>>> class=" org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditor Part "
>>>
> contributorClass=" org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditor ActionBarContributor "
>
>>>
>>> icon="icons/my-xml.gif"
>>> id="com.mycompany.myproduct.xml"
>>> name="My XML Editor">
>>> <contentTypeBinding
>>> contentTypeId="com.mycompany.myproduct.myXML">
>>> </contentTypeBinding>
>>> </editor>
>>> </extension>
>>> <extension
>>> point="org.eclipse.wst.xml.core.catalogContributions">
>>> <catalogContribution>
>>> <uri
>>> name="http://www.mycompany.com/myproduct/2009/XMLSchema"
>>> uri="schema/myXML.xsd">
>>> </uri>
>>> </catalogContribution>
>>> </extension>
>>>
>>> --------------------------
>>>
>>> My schema/myXML.xsd looks like:
>>>
>>> <?xml version="1.0" encoding="UTF-8"?>
>>> <schema
>>> targetNamespace="http://www.mycompany.com/myproduct/2009/XMLSchema"
>>> xmlns="http://www.w3.org/2001/XMLSchema"
>>> xmlns:tns="http://www.mycompany.com/myproduct/2009/XMLSchema">
>>>
>>> <element name="myRoot">
>>> <complexType>
>>> <sequence>
>>> <element name="myEntry1" type="tns:EntryType"
>>> maxOccurs="unbounded" minOccurs="0" />
>>> <element name="myEntry2" type="tns:EntryType"
>>> maxOccurs="unbounded" minOccurs="0" />
>>> ...
>>> </sequence>
>>> </complexType>
>>> </element>
>>>
>>> <complexType name="EntryType">
>>> <choice maxOccurs="unbounded" minOccurs="0">
>>> <element name="data" type="tns:DoubleValueType" maxOccurs="1"
>>> minOccurs="1" />
>>> <element name="data" type="tns:IntegerValueType" maxOccurs="1"
>>> minOccurs="1" />
>>> </choice>
>>> <attribute name="index" type="int" use="optional" />
>>> <attribute name="size" type="int" use="optional" />
>>> </complexType>
>>>
>>> <complexType name="DoubleValueType">
>>> <complexContent>
>>> <extension base="tns:HexValueType">
>>> <attribute name="value" type="double" use="required" />
>>> <attribute name="type" use="optional">
>>> <simpleType>
>>> <restriction base="string">
>>> <pattern value=" " />
>>> </restriction>
>>> </simpleType>
>>> </attribute>
>>> </extension>
>>> </complexContent>
>>> </complexType>
>>>
>>> <complexType name="IntegerValueType">
>>> <complexContent>
>>> <extension base="tns:HexValueType">
>>> <attribute name="value" type="int" use="required" />
>>> <attribute name="type" use="required">
>>> <simpleType>
>>> <restriction base="string">
>>> <pattern value="[iI]" />
>>> </restriction>
>>> </simpleType>
>>> </attribute>
>>> </extension>
>>> </complexContent>
>>> </complexType>
>>>
>>> ...
>>>
>>> </schema>
>>>
>>>
>
>
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05254 seconds