0
votes

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);

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);

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>

How can I prevent the generation of the EntityType's namespace?

1

1 Answers

1
votes

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.