当我尝试创建一个Attribute时,我收到了这个DOMException。
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(Unknown Source)
at com.sun.org.apache.xerces.internal.dom.AttrNSImpl.<init>(Unknown Source)
at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.createAttributeNS(Unknown Source)
at xml.XmlCreator.dom(XmlCreator.java:308)
at xml.XmlCreator.readTestSetRecordsForXmlFile(XmlCreator.java:262)
at xml.XmlCreator.createFile(XmlCreator.java:112)
at xml.XmlCreator.doInBackground(XmlCreator.java:83)
at xml.XmlCreator.doInBackground(XmlCreator.java:1)
at javax.swing.SwingWorker$1.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at javax.swing.SwingWorker.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
我的代码:
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
docFactory.setNamespaceAware(true);
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.newDocument();
DOMSource source = new DOMSource(doc);
Attr attributeNS = doc.createAttributeNS(attributeNS(rsValues)[1], attributeNS(rsValues)[0]);
attributeNS(rsValues)[1]
返回urn:iso:std:iso:20022:tech:xsd:pacs.003.001.02
attributeNS(rsValues)[1]
返回xmlns
造成这种情况的原因是什么?