Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   XML (http://www.velocityreviews.com/forums/f32-xml.html)
-   -   Reomoval of name space attribute (http://www.velocityreviews.com/forums/t169514-reomoval-of-name-space-attribute.html)

davisjoseph@postmark.net 06-27-2005 08:23 AM

Reomoval of name space attribute
 
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


Martin Honnen 06-27-2005 12:43 PM

Re: Reomoval of name space attribute
 


davisjoseph@postmark.net wrote:


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

--

Martin Honnen
http://JavaScript.FAQTs.com/


All times are GMT. The time now is 04:06 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57