[
http://issues.apache.org/jira/browse/JELLY-213?page=comments#action_12315291 ]
Diogo Bacelar Quintela commented on JELLY-213:
----------------------------------------------
Jelly Script
############ (TestNs.jelly)
<?xml version="1.0" encoding="UTF-8"?>
<j:jelly xmlns:j="jelly:core" xmlns:x="jelly:xml">
<one>
<x:element URI="http://apache/testNS" name="two">
<x:attribute URI="http://apache/anotherNS"
name="test:abc2"
trim="true">
testValue
</x:attribute>
<three>hi</three>
</x:element>
</one>
</j:jelly>
##############
NOTES: Element "one" has no default namespace because j:jelly does not define
one, so nor does element "three".
Element "two" should be declared to be in namespace "http://apache/testNS"
The namespace URI set for ElementTag don't get reset if using a no
dom4j-XMLOutput, and exists before patch 1
(http://issues.apache.org/jira/browse/JELLY-213, jelly-xml.patch)
because ElementTag already allows to set a namespace.
See bellow "SAMPLE OUTPUTS"
Java Test
######### (TestNs.java)
import java.io.File; import java.io.IOException; import
java.io.OutputStreamWriter; import java.io.StringWriter; import java.io.Writer;
import java.net.URL; import org.apache.commons.jelly.JellyContext; import
org.apache.commons.jelly.JellyException; import
org.apache.commons.jelly.XMLOutput; import org.apache.xml.serialize.Method;
import org.apache.xml.serialize.OutputFormat; import
org.apache.xml.serialize.XMLSerializer; import org.dom4j.io.SAXContentHandler;
import org.dom4j.io.SAXReader; import org.dom4j.io.XMLWriter; import
org.xml.sax.SAXException;
public class TestNs {
public TestNs() {
}
public void serializeUsingSimpleXMLOutput(
String fileName,
Writer writer)
throws JellyException, IOException {
JellyContext context = new JellyContext();
// cature the output
// XMLOutput output = XMLOutput.createXMLOutput(writer);
org.dom4j.io.OutputFormat outputFormat =
new org.dom4j.io.OutputFormat();
outputFormat.setSuppressDeclaration(true);
outputFormat.setNewlines(true);
outputFormat.setIndent(true);
outputFormat.setIndentSize(4);
XMLWriter xmlWriter = new XMLWriter(writer, outputFormat);
XMLOutput output = new XMLOutput(xmlWriter);
URL fUrl = getClass().getResource(fileName);
context.runScript( fUrl, output );
//xmlWriter.close();
output.flush();
writer.write('\n');
writer.flush();
}
public void serializeUsingSAXContentHandler(
String fileName,
Writer writer)
throws IOException, JellyException, SAXException {
org.dom4j.io.OutputFormat outputFormat =
new org.dom4j.io.OutputFormat();
outputFormat.setSuppressDeclaration(true);
outputFormat.setNewlines(true);
outputFormat.setIndent(true);
outputFormat.setIndentSize(4);
XMLWriter xmlWriter = new XMLWriter(writer, outputFormat);
xmlWriter.setEscapeText(false);
SAXContentHandler saxHandler = new SAXContentHandler();
XMLOutput output = new XMLOutput(saxHandler);
// now run a script using a URL
JellyContext context = new JellyContext();
URL fUrl = getClass().getResource(fileName);
output.startDocument();
context.runScript(fUrl, output);
output.endDocument();
xmlWriter.write(saxHandler.getDocument());
xmlWriter.flush();
}
public static void main(String[] args) {
try {
TestNs t = new TestNs();
Writer someWriter = new OutputStreamWriter(System.out);
System.out.println("------");
t.serializeUsingSAXContentHandler("TestNs.jelly", someWriter);
System.out.println("------");
t.serializeUsingSimpleXMLOutput("TestNs.jelly", someWriter);
System.out.println("------");
} catch (Exception e) {
e.printStackTrace();
}
}
}
#########
NOTES:
serializeUsingSAXContentHandler uses dom4j facilities
serializeUsingSimpleXMLOutput does not
SAMPLE OUTPUTS
##############
With PATCH 1 (http://issues.apache.org/jira/browse/JELLY-213, jelly-xml.patch).
As Paul said, imcomplete because of lack of use of
startPrefixMapping/endPrefixMapping
### OUTPUT ###
------
<one>
<two xmlns="http://apache/testNS"
xmlns:test="http://apache/anotherNS"
test:abc2="testValue">
<three xmlns="">hi</three>
</two>
</one>
------
<one>
<two test:abc2="testValue">
<three>hi</three>
</two>
</one>
------
##############
With PATCH 2 (http://issues.apache.org/jira/browse/JELLY-213,
jelly-xml-updated.patch).
startPrefixMapping/endPrefixMapping as possible, presenting better results.
Problem. XMLOutput doesn't have state, JellyPipeline doesn't allow to when
"two" element is used, when know what was
the previous namespace to reset it's value as it's done in trunk 1 bellow for
element "three"
### OUTPUT ###
------
<one>
<two xmlns="http://apache/testNS"
xmlns:test="http://apache/anotherNS"
test:abc2="testValue">
<three xmlns="">hi</three>
</two>
</one>
------
<one>
<two xmlns:test="http://apache/anotherNS"
xmlns="http://apache/testNS"
test:abc2="testValue">
<three>hi</three>
</two>
</one>
------
##############
SAXContentHandler manage state of parsing so it's able handle well with the
situation,
as seen in trunk 1 of above output.
Discussion:
Should we discard PATCH 2 and let the client XMLOutput responsible for this
handling ?
If soo, for sake of XMLOutput factory methods coeherence, shall we modify
XMLOutput.createXMLOutput(Writer[,boolean]) and
XMLOutput.createXMLOutput(OutputStream[,boolean])
to follow the aproach given in "serializeUsingSAXContentHandler method in java
sample" ?
> 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-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]