Error while creating a namespace for xml node
Document doc = docBuilder.newDocument();
Element rootElement = doc.createElement("GovTalkMessage");
rootElement.setAttributeNS("http://www.govtalk.gov.uk/schemas/govtalk/govtalkheader",
"xmlns", "Test");
doc.appendChild(rootElement);
i get following error when i am trying to give namespace to existing xml
element
Exception in thread "main" org.w3c.dom.DOMException: NAMESPACE_ERR: An
attempt is made to create or change an object in a way which is incorrect
with regard to namespaces.
at
com.sun.org.apache.xerces.internal.dom.AttrNSImpl.setName(AttrNSImpl.java:109)
at
com.sun.org.apache.xerces.internal.dom.AttrNSImpl.<init>(AttrNSImpl.java:78)
at
com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.createAttributeNS(CoreDocumentImpl.java:2142)
at
com.sun.org.apache.xerces.internal.dom.ElementImpl.setAttributeNS(ElementImpl.java:659)
at try_code.main(try_code.java:26)
Java Result: 1
No comments:
Post a Comment