HI! We used createElementNS() in 2.0.1 successfully. Since we switched to newer versions (now 2.4.0), it stopped working as expected. We have reviewed our code and changed it as suggested in http://nagoya.apache.org/bugzilla/show_bug.cgi?id=7687 with no positive effect.
Using 2.0.1, the test code below produces: <root><testNode xmlns="http://schemas.p2plus.com/test/"/></root> <root><testNode xmlns="http://schemas.p2plus.com/test/"/></root> Using 2.4.0, the test code below produces: <root><testNode/></root> <root><testNode xmlns=""/></root> Any help would be greatly appreciated. Thanks! Regards, Thomas Test code: ---------- import java.io.*; import javax.xml.parsers.*; import org.apache.xml.serialize.*; import org.w3c.dom.*; import org.xml.sax.*; public class NamespaceTest { public static void main(String[] args) throws Exception { Document doc; Element root, tag; Attr attr; String namespaceURI = "http://schemas.p2plus.com/test/"; String tagName = "testNode"; doc = getDocument("<root />"); root = doc.getDocumentElement(); tag = doc.createElementNS(namespaceURI, tagName); root.appendChild(tag); System.out.println(docToString(doc)); doc = getDocument("<root />"); root = doc.getDocumentElement(); tag = doc.createElementNS(namespaceURI, tagName); attr = doc.createAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns"); tag.setAttributeNodeNS(attr); root.appendChild(tag); System.out.println(docToString(doc)); } public static Document getDocument(String xml) throws Exception { DocumentBuilderFactory dbf; DocumentBuilder db; Document doc; dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); dbf.setValidating(true); dbf.setAttribute("http://apache.org/xml/features/validation/dynamic", new Boolean(true)); dbf.setAttribute("http://apache.org/xml/features/validation/schema", new Boolean(true)); db = dbf.newDocumentBuilder(); doc = db.parse(new InputSource(new StringReader(xml))); return(doc); } public static String docToString(Document doc) throws Exception { OutputFormat outputFormat; XMLSerializer xmlSerializer; StringWriter sw; try { sw = new StringWriter(); outputFormat = new OutputFormat(); outputFormat.setOmitXMLDeclaration(true); outputFormat.setEncoding("utf-16"); outputFormat.setPreserveSpace(true); xmlSerializer = new XMLSerializer(sw, outputFormat); xmlSerializer = new XMLSerializer(sw, outputFormat); xmlSerializer.serialize(doc); return(sw.toString()); } catch (IOException ioe) { return(ioe.getMessage()); } } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
