HI! Thanks a lot! This works.
Regards, Thomas > -----Original Message----- > From: Sander Bos [mailto:[EMAIL PROTECTED] > Sent: Montag, 26. Mai 2003 16:02 > To: [EMAIL PROTECTED] > Subject: RE: createElementNS() does not work as expected in > new versions of Xerces (> 2.0.1) > > > > Dear Thomas, > > For the second part of the test, this is probably something > in the order > in which the serializer handled things. Your code has a bug I think, > > > attr = doc.createAttributeNS("http://www.w3.org/2000/xmlns/", > "xmlns"); > > tag.setAttributeNodeNS(attr); > > You do not actually set your namespace on the attribute as > the value, so > I would put > attr.setValue(namespaceURI); > between the two lines. > > (Why the first test without explicitly setting the attribute does not > work I do not know) > > Kind regards, > > --Sander. > > > > > -----Original Message----- > > From: Thomas B�rkel [mailto:[EMAIL PROTECTED] > > Sent: 26 May, 2003 3:32 PM > > To: Xerces Mailinglist > > Subject: createElementNS() does not work as expected in new > > versions of > > Xerces (> 2.0.1) > > > > > > 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] > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
