如何防止名称空间生成? [英] How to prevent the namespace generation?
问题描述
我正在创建具有根Application
和默认名称空间的XML文档,如下所示:
I am creating an XML document with the root Application
and a default namespace like this:
var doc = document.implementation.createDocument ('http://AOR-AppML.org', 'Application', null);
稍后,我添加一个子元素EntityType
.问题是http://www.w3.org/1999/xhtml
命名空间是为此元素自动生成的,我不希望这种情况发生.创建和添加此元素的代码是:
Later I add a child element EntityType
. The problem is that the http://www.w3.org/1999/xhtml
namespace is automatically generated for this element and I don't want this to happen. The code for creating and adding this element is:
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文件中,该文件的内容为:
Then I save the generated code in an XML file and the content of the file is:
<Application xmlns="http://AOR-AppML.org" name="SoRiN">
<EntityType xmlns="http://www.w3.org/1999/xhtml" name="EntityType"></EntityType>
</Application>
如何防止EntityType命名空间的生成?
How can I prevent the generation of the EntityType's namespace?
推荐答案
全局文档"对象具有默认名称空间,因此您需要使用生成的"doc"对象创建其他元素.
The global 'document' object has a default namespace so you need to create the other elements using the 'doc' object you built.
var entityTypeNode = doc.createElement('EntityType');
这样,还可以在您标识的名称空间中创建元素.
That way the elements are also created in the namespace you identified.
这篇关于如何防止名称空间生成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!