[ http://issues.apache.org/jira/browse/JELLY-213?page=all ]
Diogo Bacelar Quintela updated JELLY-213: ----------------------------------------- Attachment: jelly-patch3.patch Here is patch3 :) AtributeTag and ElementTag are exactly the same as patch 1 XMLOutput now has a stack of namespaces, and manages the calls to startPrefixMapping and endPrefixMapping. It passes common testcases and jelly-xml testcases (haven't tried the others :) It now generates equivalent outputs in both cases (described in above java class TestNS) [equivalent means equivalent xml, not necessarly the same order of attributes]. I've included a new tag, that i mentionated some comments above. A ReplaceNamespaceTag. As it name implies, it replaces all namespaces from one uri to another in its body (fromURI and toURI properties). XMLOutput does it job perfectly, again :) Ex: <?xml version="1.0" encoding="UTF-8"?> <j:jelly xmlns:j="jelly:core" xmlns:x="jelly:xml"> <x:element URI="${ns}" name="test-node"> <x:attribute URI="http://apache/testNS" name="test:abc" trim="true">testValue</x:attribute> <test-subnode attr="test"> <test-anotherSubNode /> <x:element URI="${ns}" name="test-anotherSubNodeAgain"> <x:attribute URI="${ns}" name="other:abc" trim="true">testValue</x:attribute> </x:element> </test-subnode> <x:replaceNamespace toURI="${ns}"> <test-subnode attr="test"> <test-anotherSubNode /> <x:element URI="${ns}" name="test-anotherSubNodeAgain"> <x:attribute URI="${ns}" name="other:abc" trim="true">testValue</x:attribute> </x:element> </test-subnode> </x:replaceNamespace> </x:element> </j:jelly> Generates When 'ns' is empty/inexistent <test-node xmlns:test="http://apache/testNS" test:abc="testValue"> <test-subnode attr="test"> <test-anotherSubNode> </test-anotherSubNode> <test-anotherSubNodeAgain xmlns:other="" other:abc="testValue"> </test-anotherSubNodeAgain> </test-subnode> </test-node> And when 'ns' if for example 'http://java/ns' <test-node xmlns:test="http://apache/testNS" xmlns="http://java/ns" test:abc="testValue"> <test-subnode xmlns="" attr="test"> <test-anotherSubNode> </test-anotherSubNode> <test-anotherSubNodeAgain xmlns:other="http://java/ns" xmlns="http://java/ns" other:abc="testValue"> </test-anotherSubNodeAgain> </test-subnode> <test-subnode attr="test"> <test-anotherSubNode> </test-anotherSubNode> <test-anotherSubNodeAgain xmlns:other="http://java/ns" other:abc="testValue"> </test-anotherSubNodeAgain> </test-subnode> </test-node> Usefull ? I'll demonstrate with my example. I am working in ejb plugin for xdoclet-plugins project, the plugins for xdoclet2 project. plugin.version.isDtd says true if we need an dtd, false, if we are using a schema. If we are using a dtd, we don't need a namespace, if we are using a schema we need to use 'http://java.sun.com/xml/ns/j2ee' as default namespace. So plugin.version.ns return null when is a dtd, and 'http://java.sun.com/xml/ns/j2ee' when its not. With this 'replaceNamespace' tag we can use the default namespace in jelly script, (replacing "" for "" let's it exactly the same :D) for dtd output, and when plugin.version.ns is http://java.sun.com/xml/ns/j2ee all nodes get automatically updated to that namespace. It will be usefull for xdoclet-plugins, and maybe for other projects. <?xml version="1.0" encoding="UTF-8"?> <j:jelly xmlns:j="jelly:core" xmlns:x="jelly:xml" xmlns:jsl="jelly:jsl"> <j:if test="${plugin.version.isDtd()}"> <x:doctype name="ejb-jar" publicId="${plugin.version.publicId}" systemId="${plugin.version.systemId}" trim="true" /> </j:if> <x:element URI="${plugin.version.ns}" name="ejb-jar"> <j:if test="${!plugin.version.isDtd()}"> <x:attribute URI="${plugin.version.xsiNs}" name="xsi:schemaLocation" trim="true">${plugin.version.schemaLocation}</x:attribute> <x:attribute name="version" trim="true">${plugin.version.version}</x:attribute> </j:if> <x:replaceNamespace toURI="${plugin.version.ns}" includeAttributes="true"> <enterprise-beans> <j:forEach var="class" items="${metadata}"> <j:if test="${plugin.shouldGenerate(class)}"> <entity> <ejb-name>${plugin.ejbUtils.getEjbName(class)}</ejb-name> .... </entity> </j:if> </j:forEach> </enterprise-beans> </x:replaceNamespace> <j:import uri="org/xdoclet/plugin/ejb/descriptor/entity-beans.jelly" inherit="true"/> </x:element> <!--</ejb-jar> --> </j:jelly> If this patch is usefull as a full (as i think it is), i'd be happy to known when it gets added to jelly project, and jelly-xml. > Generating xml nodes with attributes in diferente namespaces (for schemas..) > ---------------------------------------------------------------------------- > > Key: JELLY-213 > URL: http://issues.apache.org/jira/browse/JELLY-213 > Project: jelly > Type: Bug > Reporter: Diogo Bacelar Quintela > Attachments: jelly-patch3.patch, jelly-xml-updated.patch, jelly-xml.patch > > I tried to find some info googling around and in the faq and couldn't find > the answer, so here it goes. > I need to generate the following xml (it's a sample off course), to support > schemas. > ------------------------------------------------ > <NodeName > xmlns="http://blah/bleh" > xmlns:xsi="http://www.w3.org/2001/XMLSchema" > xsi:schemaLocation="http://blah/blehSchemaLocation"> > <!-- Other content here --> > </NodeName> > ------------------------------------------------ > After several tries and some inconsistent behaviour, I thought the following > jelly excerpt should be close to the solution, however "xml:attribute" > doesn't support namespaces values. > ------------------------------------------------ > <j:jelly xmlns:j="jelly:core" xmlns:x="jelly:xml"> > <x:element URI="${myns}" name="NodeName"> > <x:attribute > name="xsi:schemaLocation" > URI="${myxsins}" > trim="true"> > ${myschemaloc} > </x:attribute> > <!-- Other content here --> > <x:element> > </j:jelly> > Where > "myns" is for example http://blah/bleh > "myschemaloc" is for example http://blah/blehSchemaLocation > "myxsins" is for example http://www.w3.org/2001/XMLSchema > ------------------------------------------------ > Is there any known solution for this problem? Even if working only for > schemas? -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]