Announcement Announcement Module
Collapse
No announcement yet.
Problems resolving XSD for custom namespace schema in STS Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problems resolving XSD for custom namespace schema in STS

    I have a project where I created a custom namespace for Spring configuration (pretty simple, it lets you specify a site map with <node> elements). I have this working in an isolated project where I did the initial development. Basically, I have an XSD, a couple of bean classes, a namespace handler, a bean definition parser, then the spring.handlers, spring.schema, and spring.tooling files. You can see how this works in the attached sample code. Just import that project into STS and it should work.

    This all works great until I try to merge this into my larger framework project. At that point, something goes wrong. The exact same code fails when I move it over there. The nature of the failure's pretty easy to understand, it's the WHY of the failure that's the problem. Basically in that project, instead of mapping the namespace to the XSD file, it goes to the URI online. I can tell because the errors contain all this stuff about CSS styles:

    Code:
    Description	Resource	Path	Location	Type
    Referenced file contains errors (http://www.rick.org/schema/rix/rix.xsd).  For more information, right click on the message in the Problems View and select "Show Details..."	TestSiteMap-context.xml	/TIP/src/test/java/org/rick/framework/sitemap	line 1	XML Problem
    s4s-elt-character: Non-whitespace characters are not allowed in schema elements other than 'xs:appinfo' and 'xs:documentation'. Saw ';}'.	TestSiteMap-context.xml	/TIP/src/test/java/org/rick/framework/sitemap	line 71	Spring Beans Problem
    s4s-elt-character: Non-whitespace characters are not allowed in schema elements other than 'xs:appinfo' and 'xs:documentation'. Saw '.adblock {padding-top: 5px; padding-left:10px; padding-bottom:5px;}'.	TestSiteMap-context.xml	/TIP/src/test/java/org/rick/framework/sitemap	line 34	Spring Beans Problem
    s4s-elt-character: Non-whitespace characters are not allowed in schema elements other than 'xs:appinfo' and 'xs:documentation'. Saw '.blackbullet{margin-bottom: 3px; margin-left: 7px; margin-right: 7px;}'.	TestSiteMap-context.xml	/TIP/src/test/java/org/rick/framework/sitemap	line 28	Spring Beans Problem
    s4s-elt-character: Non-whitespace characters are not allowed in schema elements other than 'xs:appinfo' and 'xs:documentation'. Saw '.clear { clear:both;}'.	TestSiteMap-context.xml	/TIP/src/test/java/org/rick/framework/sitemap	line 26	Spring Beans Problem
    s4s-elt-character: Non-whitespace characters are not allowed in schema elements other than 'xs:appinfo' and 'xs:documentation'. Saw '.footerlink1{font-size: 11px; color: #1637AA;}'.	TestSiteMap-context.xml	/TIP/src/test/java/org/rick/framework/sitemap	line 29	Spring Beans Problem
    Note that, if you get this same behavior with the provided sample code (I don't think you will, as I've tried this on multiple machines; projects that work on one machine work on another, while the project that fails fails elsewhere as well), you'll see a different message:

    Code:
    Open quote is expected for attribute "align" associated with an  element type  "div".	TestSiteMap-context.xml
    I've used a different URL in the sample I've provided just to change the company name in the code. But the point is that it's going out and trying to download the XSD instead of resolving it to the XSD file specified in the spring.schemas.

    What's frustrating about this is that it WORKS in some cases and fails in the other, all with the same code and in the same workspace (so it's not a workspace setting, and no entering the namespace URI into the XML catalog doesn't fix the issue). I've done a file-by-file compare and can't see any project settings that are appreciably different that should cause this behavior.

    The final test is that I can do a Maven build of the project that's failing in STS and it builds successfully! So there's nothing in the code itself. This has to be an STS issue, but I can't for the life of me figure out what's going on. Any help would be greatly appreciated.

  • #2
    Rick,

    what version of STS are you using? If you are on anything < 2.3.1 (not released yet) STS will not resolve namespaces and XSDs from the project's classpath.

    So I would assume that this isn't working in any case.

    In your sample code the TestSiteMap-context.xml is not configured to be a Spring configuration file with STS. That is most likely why you don't see this error in that project. Once I configure the test file to be a Spring Config I get the same error as you posted.

    The good news is that with STS 2.3.1 nightly snapshots you are able to use the namespace parsers and xsds from your project's classpath.

    If you want to try that out, please update the Spring IDE components of STS from the following update site: http://dist.springframework.org/snapshot/IDE/nightly

    After your update you'll find a new setting in the project configuration: Spring -> Beans Support -> "Load NamespaceHandlers and XSDs from project's classpath [experimental]". Enable this and you should be all set.

    Let me know if that helps.

    Christian

    Comment


    • #3
      Christian,

      Thanks for the quick response. I'm using 2.3.0. I think the issue is that I pushed the configuration file into the project directly from my XML editor instead of adding it with the New->Spring Bean Configuration File operation as per normal. Once I right-clicked on it and selected the Validate command, I got the same error there, so that's exactly the issue.

      What I find weird about the behavior is that, as long as STS just sees it as a plain ol' XML file, the custom namespaces work fine. And I don't just mean that it doesn't give me errors, but that I can do Ctrl-Space to complete element names, add attributes, etc.

      Anyways, I'll try 2.3.1 and use that. The problem is that I have to check this code in and can't expect everyone in our development group to upgrade to an unreleased snapshot version. Can you say what the 2.3.1 release timeline is?

      Comment


      • #4
        Rick,

        I expect STS 2.3.1 to come out with the next two weeks.

        When you say the "custom namespace work fine" I guess you mean content assist in the XML editor. If you look closely you'll notice that you'll only get content assist proposals for elements and attributes that are in your XML file.

        Furthermore you don't see beans created by the namespace handler in the Spring Explorer and no validation of the namespace elements happens. All this will spring to life with 2.3.1.

        Christian

        Comment


        • #5
          Great, thanks for the information!

          Comment

          Working...
          X