Your code is correct, and will set the namespace and prefix. I am slightley worried, however, that you say your element, when output, was in the wrong namespace. I suspect a bug in the namespace normalization code, if you are correct.
I am mainly a xerces-c user, but does anyone know the state of the normalization code in xerces-j? Dennis Sosnoski wrote: > > Thanks for the response, John. However, if I don't set the prefix the added > element > just shows up in the default namespace when the document is output as text. > Am I > missing something here? > > The original code generated the correct XML output document text for all the > cases I > tried, but I didn't look at the internal state (only the output). I guess > what I > really should do to make this correct is use the prefix from the parent > element to > construct the name of the new element (if the prefix is not null), then > always use > createElementNS to create the new element: > > String name = (prefix == null) ? "text" : (prefix + ":text"); > Element text = doc.createElementNS(element.getNamespaceURI(), name); > > Any problem with that? > > Thanks again, > > - Dennis > > John Snelson wrote: > > > You can have an element whose prefix is null, but is still in a > > namespace. Why not try this? > > > > Element text = > > element.getOwnerDocument().createElementNS(element.getNamespaceURI(), > > "text"); > > > > This should work in all cases, but please note that it does not set the > > prefix of the "text" element. > > > > John -- John Snelson, Software Engineer DecisionSoft Ltd. Telephone: +44-1865-203192 http://www.decisionsoft.com --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
