You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by xa...@xml.apache.org on 2004/10/05 23:18:33 UTC
[jira] Commented: (XALANJ-1410) I cannot use dummy transform technique to serialize a document with namespaces
The following comment has been added to this issue:
Author: Yash Talwar
Created: Tue, 5 Oct 2004 2:17 PM
Body:
Hello Ramesh,
You wrote:
"I prefer to get this code with work with dummy XSLT transformer so that I do not have to use native Xerces API. Instead, my code will only use JAXP interface and everything happens behind the scenes."
When I used the dummy XSLT transformer from the java class you provided, I got following output with Xalan 2.6.0 (currentCVS).
Serialize With Dummy Transform:
<?xml version="1.0" encoding="UTF-8"?>
<mspm:rootelement xmlns:mspm="http://rsakala">
<mspm:element mspm2:mspm2attr2="attrvalue2" mspm:mspmattr1="attrvalue1"/>
</mspm:rootelement>
Is this expected behaviour?
Thanks!
---------------------------------------------------------------------
View this comment:
http://issues.apache.org/jira/browse/XALANJ-1410?page=comments#action_53730
---------------------------------------------------------------------
View the issue:
http://issues.apache.org/jira/browse/XALANJ-1410
Here is an overview of the issue:
---------------------------------------------------------------------
Key: XALANJ-1410
Summary: I cannot use dummy transform technique to serialize a document with namespaces
Type: Bug
Status: Open
Project: XalanJ2
Components:
JAXP
Versions:
2.4
Assignee: Xalan Developers Mailing List
Reporter: Ramesh Sakala
Created: Thu, 30 Jan 2003 5:50 PM
Updated: Tue, 5 Oct 2004 2:17 PM
Environment: Operating System: Windows NT/2K
Platform: PC
Description:
I am creating a DOM document with JAXP interface with namespace elements and
attributes. I am seeing different behavior with different versions of Xerces
versions; None of them except version 2.0.1 seems to be correct.
With version 2.3.0 and 2.2.1:
If I use XMLSerializer, I do not get the namespace attributes.
If I use the DOM3 procedure, I get the namespace attributes; but all of the
elements have the namespace attributes unnecessarily instead of having it once
on the root node.
If I use a dummy XSLT transformer with DOM source and Stream result, I do not
get any namespace nodes.
With version 2.0.1:
If I use XMLSerializer, I get the namespace attributes properly.
If I use a dummy XSLT transformer with DOM source and Stream result, I do not
get any namespace nodes.
I prefer to get this code with work with dummy XSLT transformer so that I do
not have to use native Xerces API. Instead, my code will only use JAXP
interface and everything happens behind the scenes.
I have attached the code I wrote below.
Here is exact result I am seeing with different xerces parsers.
With Xerces2.0.1.jar, I see the following in System.out
_________________
Serialize With Dummy Transform:
<?xml version="1.0" encoding="UTF-8"?>
<mspm:rootelement><mspm:element mspm2:mspm2attr2="attrvalue2"
mspm:mspmattr1="attrvalue1"/></mspm:rootelement>
Serialize With FAQ2 Help:
<?xml version="1.0" encoding="UTF-8"?>
<mspm:rootelement xmlns:mspm="http://rsakala"><mspm:element
xmlns:mspm2="http://rsakala2" mspm2:mspm2attr2="attrvalue2"
mspm:mspmattr1="attrvalue1"/></mspm:rootelement>
_________________
With Xerces 2.2.1.jar, I see the following in System.out
_________________
Serialize With Dummy Transform:
<?xml version="1.0" encoding="UTF-8"?>
<mspm:rootelement><mspm:element mspm2:mspm2attr2="attrvalue2"
mspm:mspmattr1="attrvalue1"/></mspm:rootelement>
Serialize With FAQ2 Help:
<?xml version="1.0" encoding="UTF-8"?>
<mspm:rootelement><mspm:element mspm2:mspm2attr2="attrvalue2"
mspm:mspmattr1="attrvalue1"/></mspm:rootelement>
Serialize With FAQ3 Help:
<?xml version="1.0"?>
<mspm:rootelement xmlns:mspm="http://rsakala"><mspm:element
xmlns:mspm="http://rsakala" xmlns:mspm2="http://rsakala2"
mspm2:mspm2attr2="attrvalue2" mspm:mspmattr1="attrvalue1"/></mspm:rootelement>
_________________
With Xerces 2.3.0.jar, I see the following in System.out
_________________
Serialize With Dummy Transform:
<?xml version="1.0" encoding="UTF-8"?>
<mspm:rootelement><mspm:element mspm2:mspm2attr2="attrvalue2"
mspm:mspmattr1="attrvalue1"/></mspm:rootelement>
Serialize With FAQ2 Help:
<?xml version="1.0" encoding="UTF-8"?>
<mspm:rootelement><mspm:element mspm2:mspm2attr2="attrvalue2"
mspm:mspmattr1="attrvalue1"/></mspm:rootelement>
Serialize With FAQ3 Help:
<?xml version="1.0"?>
<mspm:rootelement xmlns:mspm="http://rsakala"><mspm:element
xmlns:mspm="http://rsakala" xmlns:mspm2="http://rsakala2"
mspm2:mspm2attr2="attrvalue2" mspm:mspmattr1="attrvalue1"/></mspm:rootelement>
_________________
Source code for the java class:
______________
import java.io.Writer;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.apache.xerces.dom3.DOMImplementationRegistry;
import org.apache.xml.serialize.LineSeparator;
import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.XMLSerializer;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.ls.DOMImplementationLS;
import org.w3c.dom.ls.DOMWriter;
public class TextXML {
public static void main(String[] args) {
try {
Document doc = buildXMLDoc();
serializeWithDummyTransform(doc);
serializeWithDOM2FAQHelp(doc);
serializeWithDOM3FAQHelp(doc);
} catch (Exception ex) {
ex.printStackTrace();
}
}
private static Document buildXMLDoc() throws Exception {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance
();
DocumentBuilder db = dbf.newDocumentBuilder();
dbf.setNamespaceAware(true);
dbf.setValidating(false);
Document doc = db.newDocument();
Element elem = doc.createElementNS
("http://rsakala", "mspm:rootelement");
doc.appendChild(elem);
Element elem2 = doc.createElementNS
("http://rsakala", "mspm:element");
elem2.setAttributeNS
("http://rsakala", "mspm:mspmattr1", "attrvalue1");
elem2.setAttributeNS
("http://rsakala2", "mspm2:mspm2attr2", "attrvalue2");
elem.appendChild(elem2);
return doc;
}
private static void serializeWithDummyTransform(Document doc)
throws Exception {
System.out.println("Serialize With Dummy Transform:");
TransformerFactory trFactory = TransformerFactory.newInstance();
Transformer tr = trFactory.newTransformer();
javax.xml.transform.dom.DOMSource domSrc =
new javax.xml.transform.dom.DOMSource(doc);
Writer writer = new java.io.StringWriter();
javax.xml.transform.stream.StreamResult strRes =
new javax.xml.transform.stream.StreamResult(writer);
tr.transform(domSrc, strRes);
System.out.println(writer.toString());
}
private static void serializeWithDOM2FAQHelp(Document doc) throws
Exception {
System.out.println("Serialize With FAQ2 Help: ");
OutputFormat format = new OutputFormat(doc);
format.setLineSeparator(LineSeparator.Windows);
format.setIndenting(true);
format.setLineWidth(0);
format.setPreserveSpace(true);
Writer writer = new java.io.StringWriter();
XMLSerializer serializer = new XMLSerializer(writer, format);
serializer.asDOMSerializer();
serializer.serialize(doc);
System.out.println(writer.toString());
}
private static void serializeWithDOM3FAQHelp(Document doc) throws
Exception {
System.out.println("Serialize With FAQ3 Help: ");
System.setProperty(
DOMImplementationRegistry.PROPERTY,
"org.apache.xerces.dom.DOMImplementationSourceImpl");
DOMImplementationRegistry registry =
DOMImplementationRegistry.newInstance();
DOMImplementationLS impl =
(DOMImplementationLS) registry.getDOMImplementation("LS-
Load");
DOMWriter writer = impl.createDOMWriter();
writer.writeNode(System.out, doc);
}
}
______________
---------------------------------------------------------------------
JIRA INFORMATION:
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
If you want more information on JIRA, or have a bug to report see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-dev-help@xml.apache.org