我正在尝试创建一个简单的 XML 文档,并且在将根元素添加到文档时收到上述错误。我只有一个根元素(为文档创建的第一个元素),并且在第一个 append_child() 调用时引发错误。以下是引发错误的代码(在 securityDoc.appendChild(securityDoc) 调用中):
public Document CreateSecurityHeader() throws ParserConfigurationException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
Document securityDoc = builder.newDocument();
try {
Element securityRoot = securityDoc.createElementNS("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "wsse:Security");
securityRoot.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns:wsse", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
securityRoot.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns:wsu", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
securityRoot.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns:env", "http://www.w3.org/2003/05/soap-envelope");
securityRoot.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns:wss","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
securityRoot.setAttribute("env:mustUnderstand", "1");
securityDoc.appendChild(securityDoc);
由于这是该文档中目前唯一的元素,我如何得到这个错误?我确实必须将 xalan 和 xerces 库作为该项目的依赖项作为其他东西的依赖项,这里可能存在不兼容吗?
墨色风雨
相关分类