Page 1 of 1

associate namespace URI with schema

Posted: Fri Oct 19, 2012 10:32 am
by rparree2
Hi,

I am trying to find what i would consider a basic feature, but somehow are unable to find in the program or on this forum/internet.

I have an XML file using many namespaces (used inside strict wildcards). What i need is a way of declaring namespace URIs (plural) and link them to a schema location, so that i can have code-insight and validation.

I tried "Document Type Association", but that only allows you to register a single schema (i guess for the document element). Also the tool-button "Associate Schema...." only allows a single one (furthermore this just adds a schemaLocation to the XML). I could obviously to that for each XML namespace, but i don't want to clutter up the XML document (and it anyway a bad idea to reference schemas from XML)

Is there anyway to tell oXygen "use this schema for that namespace"? Similar to other editors (e.g, IDEA IntelliJ)

Thanks.,

Re: associate namespace URI with schema

Posted: Fri Oct 19, 2012 3:19 pm
by adrian
Hello,

You haven't mentioned what types of schemas are you using, but from the context I'm guessing it's XML schema(XSD).
I'm not sure if you want to associate multiple schemas within an XML or you're just looking for a way to map namespace URis to schemas.

If it's the former (associate multiple schemas within an XML), then that's not possible directly in the XML, you need to create an additional schema that imports the others and links them together.

If it's the latter (map namespace URIs to schemas) then you could write and use an XML catalog.
You can find documentation and an example in the Oxygen user manual:
Working with XML Catalogs

Let me know if you need additional assistance.

Regards,
Adrian

Re: associate namespace URI with schema

Posted: Fri Oct 19, 2012 3:32 pm
by rparree2
Adian,

Thanks for your reply. Indeed the schemas are "W3C XML Schemas".I am looking for a tool feature (so "the latter" in your reply). BTW it is possible in XML to associate an XML document with many XSDs, With using schemaLocation you can provide a list of namespace URIs and XSD URLs. But that's what i don't want.

In fact i should have posted this in the "Common Problems" forum and not in XML. Only later i realized this is where people ask pure XML related questions.

I did try the catalog, but it does not seem to work. My catalog contents is: (catalog file in same directory as XSD files)

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE catalog PUBLIC "-//OASIS//DTD XML Catalogs V1.1//EN" "http://www.oasis-open.org/committees/entity/release/1.1/catalog.dtd">
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog" prefer="system" >
<uri name="urn:jboss:domain:1.3" uri="jboss-as-config_1_3.xsd"/>
<uri name="urn:jboss:domain:messaging:1.2" uri="jboss-as-messaging_1_2.xsd"/>
<uri name="urn:jboss:domain:modcluster:1.1" uri="jboss-as-mod-cluster_1_1.xsd"/>
....
</catalog>
And part of my XML is:

Code: Select all

<server xmlns="urn:jboss:domain:1.3">
<extensions/>
<management/>
<profile>
<subsystem xmlns="urn:jboss:domain:jsr77:1.0"/>
<subsystem xmlns="urn:jboss:domain:mail:1.0">
<mail-session jndi-name="java:jboss/mail/Default">
<smtp-server outbound-socket-binding-ref="mail-smtp"/>
</mail-session>
</subsystem>
<subsystem xmlns="urn:jboss:domain:messaging:1.2">
<hornetq-server>
</hornetq-server>
</subsystem>
<subsystem xmlns="urn:jboss:domain:naming:1.2">
<remote-naming/>
</subsystem>
<subsystem xmlns="urn:jboss:domain:remoting:1.1">
<connector name="remoting-connector" socket-binding="remoting" security-realm="ApplicationRealm"/>
</subsystem>
<subsystem xmlns="urn:jboss:domain:resource-adapters:1.0"/>
</profile>
<interfaces/>
<socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}"/>
</server>
But this does not work.

Re: associate namespace URI with schema

Posted: Fri Oct 19, 2012 5:13 pm
by adrian
Hi,
rparree2 wrote:BTW it is possible in XML to associate an XML document with many XSDs, With using schemaLocation you can provide a list of namespace URIs and XSD URLs. But that's what i don't want.
You are right, I completely forgot about that. Oxygen even supports that for content completion and validation, just not for association (Associate Schema....).

I've successfully (with some missing schemas from that catalog) tried your examples with the schemas found here:
https://github.com/jbossas/jboss-as/tre ... ocs/schema
Make sure you've added your XML catalog file in Options > Preferences, XML > XML Catalog.

Regards,
Adrian

Re: associate namespace URI with schema

Posted: Fri Oct 19, 2012 5:50 pm
by rparree2
Hi,

I don't get it, it is not working for me. Are you getting content completion for example is the element:

Code: Select all

<subsystem xmlns="urn:jboss:domain:messaging:1.2">
...
Because i don't. I have tried using the public schema locations, but that does not help either. It only seem to work on the document element. And that can also be accomplished using an oXygen framework.

I have tried with and without "Process namespaces trhough URI mappings for XML schema". With verbosity to "all", i see three "Resolved URI ..." for the namespace of the document element, but after that many "Could not resolve URI".

What am i missing?

Re: associate namespace URI with schema

Posted: Fri Oct 19, 2012 6:11 pm
by adrian
Hi,

You are right, it only works for the namespace of the root element. To make this work you have to add all the necessary namespace/schemas in the schemaLocation attribute. Since you have the catalog you can use the URI twice:
e.g.

Code: Select all

<server xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:jboss:domain:1.3 urn:jboss:domain:1.3 urn:jboss:domain:messaging:1.2 urn:jboss:domain:messaging:1.2" xmlns="urn:jboss:domain:1.3">
Regards,
Adrian

Re: associate namespace URI with schema

Posted: Fri Oct 19, 2012 6:21 pm
by rparree2
Hi,

That's just what i want to avoid. In general it is a bad idea to add these hints to the XML document. Therefore i was looking for this (by me assumed) basic feature of an XML editor.

I continue editing with IntelliJ :( (which is fine otherwise, just a bit heavy for XML authoring)

Re: associate namespace URI with schema

Posted: Fri Oct 19, 2012 8:58 pm
by adrian
Hi,

I'm not sure I understand the problem you have with URIs in the schemaLocation. It's not as if you're referring the schemas by file name (that could be a problem in some contexts), they are the same URIs that you're using in the schema to declare the namespaces. If a schema ever changes (e.g. different version), you would only have to edit the XML catalog. So what am I missing?

Regrds,
Adrian

Re: associate namespace URI with schema

Posted: Fri Oct 19, 2012 10:15 pm
by rparree2
Hi,

Not a big problem...but in general i think it is a bad idea to reference any schema from your XML, as schema languages will evolve (like DTD did), but the XML will remain. Again, not a big problem, but just something i think is a bad idea (to reference XSI). Especially if it is just a lack of features in a tool, having alternatives. In this case not a a real issue, as it is just a bunch of configuration files. I was also asking the question for more generic problems, outside the field of configuration.

Oxygen rocks for most things, therefore it was hard for me to believe that code insight and validation for multi-namespace XML would be such a problem, without relying on core XSD/XSI technologies.

Thanks for all your help, much appreciated :)