如何防止命名空间生成?

时间:2014-02-27 16:35:40

标签: javascript xml dom namespaces xml-namespaces

我正在创建一个带有根Application的XML文档和一个默认命名空间,如下所示:

var doc = document.implementation.createDocument ('http://AOR-AppML.org', 'Application', null);

稍后我添加了一个子元素EntityType。问题是为这个元素自动生成http://www.w3.org/1999/xhtml命名空间,我不希望这种情况发生。创建和添加此元素的代码是:

var entityTypeNode = document.createElement('EntityType');
var entityTypeName = document.createAttribute('name');
entityTypeName.value = secondLevelProp.properties.entitytypename; // not so important
entityTypeNode.setAttributeNode(entityTypeName);
rootEl.appendChild(entityTypeNode);

然后我将生成的代码保存在XML文件中,文件内容为:

<Application xmlns="http://AOR-AppML.org" name="SoRiN">
    <EntityType xmlns="http://www.w3.org/1999/xhtml" name="EntityType"></EntityType>
</Application>

如何防止生成EntityType的命名空间?

1 个答案:

答案 0 :(得分:1)

全局“文档”对象具有默认命名空间,因此您需要使用您构建的“doc”对象创建其他元素。

var entityTypeNode = doc.createElement('EntityType');

这样,元素也会在您标识的命名空间中创建。

相关问题