Reomoval of name space attribute

D

davisjoseph

Hi,

I'm using Xerces C++ API for XML operations. I need to remove the XML
namespace attribute from this type of XML doc,

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="http://skies.net/schema/sky"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://skies.net/schema/sky
http://http://skies.net/schema/Schema.xsd">
............
</root>

need to be
<?xml version="1.0" encoding="UTF-8"?>
<root >
.........
</root>

I tried to use removeAttributeNS() & removeAttribute()functions ; but
I'm not able to remove the attribute fully. I think I'm missing
something.Can any one provide me a small code snippet that can do this
opeartion. I'm newbie to this Xerces API.

Thanks & Regards
 
M

Martin Honnen

I'm using Xerces C++ API for XML operations. I need to remove the XML
namespace attribute from this type of XML doc,

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="http://skies.net/schema/sky"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://skies.net/schema/sky
http://http://skies.net/schema/Schema.xsd">
...........
</root>

need to be
<?xml version="1.0" encoding="UTF-8"?>
<root >
........
</root>

I tried to use removeAttributeNS() & removeAttribute()functions ; but
I'm not able to remove the attribute fully. I think I'm missing
something.Can any one provide me a small code snippet that can do this
opeartion.


It is not possible to change the namespace associated with a node after
its creation, you need to create a new node (element in this case) that
is in no namespace and then replace the original node.
JavaScript pseudo-code:

function changeElement (oldElement, newTagName) {
var newElement = oldElement.ownerDocument.createElement(newTagName);
oldElement.parentNode.replaceChild(newElement, oldElement);
while (oldElement.hasChildNodes()) {
newElement.appendChild(oldElement.firstChild);
}
}

changeElement(xmlDocument.documentElement, 'root');
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top