Element newElement = doc.createElement("ns3:element3");
createElement
is a DOM level 1 method that is not namespace aware - its JavaDoc says that it returns
A new
Element
object with thenodeName
attribute set totagName
, andlocalName
,prefix
, andnamespaceURI
set tonull
.
You need to create the new elements using the DOM level 2 createElementNS
instead
Element newElement = doc.createElementNS("urn:exo:/path/to/xsd/in/jar", "ns3:element3");
(or whatever is the correct namespace URI that corresponds to ns3
, you could get it directly from the namespace context using myNSContext.getNamespaceURI("ns3")
).