Home » Modeling » M2T (model-to-text transformation) » Error when setting "xsi:schemaLocation" attribute
|
Re: Error when setting "xsi:schemaLocation" attribute [message #50028 is a reply to message #49998] |
Thu, 18 September 2008 13:05 |
Paul Elder Messages: 849 Registered: July 2009 |
Senior Member |
|
|
Roshan:
I don't think that will work. There are several limitations at work:
First, while the JET xpath engine understands the concept of namespace
prefixes, there are no tags defined to map a prefix to an NS URI, so JET
Xpath expressions will never match an expression like:
$springContext/*/@xmlns:ehcache. Because of this, the engine is a little
lax on processing unqualified attributes, $springContext/*/@ehcache would
have chance of returning a result.
Second, the c:set tag is not recognizing a namespace prefix in 'name', and
doing something appropriate. The <c:set> tag attempts to do the following:
1) figure out what kind of object $springContext/* is, and if it can handle
the setting of an attribute calls xmlns:ehcache. None of the in-the-box
'inspector' implementations correctly handle a namespace prefix.
2) if #1 fails, then the XPath engine starts the value in a map associated
with the selected object. But, again, I don't think the namespace prefix
will be correctly han
I have seen the 'load-a-document-and-modify-it' pattern in a number of JET
transformations. So I feel that getting the XPath engine, inspectors and tag
libraries to support this better is important. But, of course, that's not
going to happen quickly. So, here are some workaround suggestions:
1) From you example, it looks like you're trying to move to the DTD-based
spring context to the XML Schema based context. If your goal is to get this
to save to disk properly, how about using a template instead...
<c:load url="spring-context.xml" var="oldSpringContext"/>
<ws:file tempate="templates/new-spring-context.xml.jet" path="..."/>
where templates/new-spring-context.xml.jet is:
------------- Start: templates/new-spring-context.xml.jet is: ----------
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5 .xsd">
<%-- copy old <bean/> definitions here --%>
<c:iterate select="$oldSpringContext/beans/bean" var="bean">
<c:dump select="$bean"/>
</c:iterate>
</beans>
------------- End: templates/new-spring-context.xml.jet is: ----------
In this case, c:dump is pretty good at maintaining the original XML below
the <bean> tags.
2) Do the modifications in a custom tag which gets directly at the
underlying model implementation. Now, <c:load> default is to use the
org.eclipse.emf.ecore.xml.type package to represent an XML document - this
API is not for mere mortals. With JET 0.9, you can get <c:load> to use the
XML DOM by specifiying:
<c:load url="spring-context.xml" var="springContext"
loader="org.eclipse.jet.xml"/>
The 'var' then points to the org.w3c.dom.Document object. So, your custom
tag could be something like:
<custom:addNS document="$springContext" prefix="xsi"
uri="http://www.w3.org/2001/XMLSchema-instance"
schemaLocation=" http://www.springframework.org/schema/beans/spring-beans-2.5 .xsd"/>
The tag implementation would do all the appropriate work directly against
the Document object.
My guess is that the second approach will be much more work for you, and it
will end up discovering more wholes in JETs support for modifying in-memory
models.
Paul
|
|
| |
Re: Error when setting "xsi:schemaLocation" attribute [message #50689 is a reply to message #50498] |
Thu, 25 September 2008 14:48 |
Paul Elder Messages: 849 Registered: July 2009 |
Senior Member |
|
|
Justin:
I think you can blame this one on EMF, which JET uses, by default, for
loading XML documents. Under the covers, EMF loads the XML schemas
referenced, generates EPackages, etc... and the tries to parse the document
and create a bunch of EObjects. I'm still looking at the EMF code, but the
attribute id on tx:advice is not defined in the tx namespace, but the
default namespace. I'm guessing that in constructing is on-the-fly ecore
packages, it is missing out on the schema-location information, and thus the
definition of id. I'll continue to look into this...
But, to move you forward...
With JET 0.9.0, XML documents can be loaded directly with the XML DOM.
Currently , this is not the default (although I'm seriously thinking about
this for the future).
To make it happen, do:
<c:load url="./templates/spring-context.xml"
var="oldSpringContext"
loader="org.eclipse.jet.xml" />
I have tested that this does, indeed load and dumpyour document.
A few caveats: I've discovered that XPath expressions such as:
$oldSpringContext/beans/advice
or
$oldSpringContext/beans/tx:advice
do not work. With EMF-based XML parsing, the XPath engine was matching
'advice' to tx:advice. But, with the XML DOM, the first expression returns
no result, and the second complains that the namespace tx is underfined. As
a workaround, you can do:
/beans/*[namespace-uri() = 'http://www.springframework.org/schema/tx' and
local-name()='advice']/@transaction-manager
Although, I must admit, this is gross. You could mitigate this by defining a
variable:
<c:setVariable var="txNS" select="
'http://www.springframework.org/schema/tx' "/>
and using the expression:
/beans/*[namespace-uri() = $txNS and
local-name()='advice']/@transaction-manager
Paul
"justin " <justin_prabhu@yahoo.com> wrote in message
news:6a8b7f95606ded07adf18752ca870cf4$1@www.eclipse.org...
> Hi Paul,
>
> Iam trying to append bean tags to existing spring config.xml.
> I have followed the approach of c:load to load xml file and then have
> xml.jet where <c:dump> is there to read it.
> I am getting error when loading spring.xml file on running JET
> transformation:
> templates/main.jet(45,2): <c:load url="./templates/spring-context.xml"
> var="oldSpringContext">
> Error: Unable to load: ./templates/spring-context.xml
> Feature 'id' not found.
> (platform:/resource/testWebtemplates/templates/spring-contex t.xml, 11, 68)
> Feature 'id' not found.
> ----- spring-context.xml file content is below ---
> <?xml version="1.0" encoding="UTF-8"?>
> <beans xmlns="http://www.springframework.org/schema/beans"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:aop="http://www.springframework.org/schema/aop"
> xmlns:tx="http://www.springframework.org/schema/tx"
> xsi:schemaLocation="
> http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans-2.0 .xsd
> http://www.springframework.org/schema/tx
> http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
> http://www.springframework.org/schema/aop
> http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
>
> <tx:advice id="txAdvice" transaction-manager="transactionManager">
> <tx:attributes>
> <tx:method name="create" propagation="REQUIRED" />
> </tx:attributes>
> </tx:advice>
> --------
> It is failing on line :<tx:advice id="txAdvice"
> transaction-manager="transactionManager">
>
> When i remove the attributes -' id="txAdvice"
> transaction-manager="transactionManager"',then the xml gets loaded.
>
> I tried this with jet 0.8 as well as JET 0.9.
>
> As we need to load existing xml,how to do this with JET. Pls let me know
> at the earliest possible as i need to complete this POC.
>
> Thanks,
> Justin.
>
>
|
|
| | | |
Goto Forum:
Current Time: Thu Nov 21 20:49:48 GMT 2024
Powered by FUDForum. Page generated in 0.04289 seconds
|