[ http://issues.apache.org/jira/browse/XALANJ-1410?page=all ]
Brian Minchau updated XALANJ-1410:
----------------------------------
Version: Latest Development Code
(was: 2.4)
> I cannot use dummy transform technique to serialize a document with namespaces
> ------------------------------------------------------------------------------
>
> Key: XALANJ-1410
> URL: http://issues.apache.org/jira/browse/XALANJ-1410
> Project: XalanJ2
> Type: Bug
> Components: JAXP
> Versions: Latest Development Code
> Environment: Operating System: Windows NT/2K
> Platform: PC
> Reporter: Ramesh Sakala
> Assignee: Xalan Developers Mailing List
>
> 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);
> }
> }
> ______________
--
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]