Removing xmlns attributes

I have an XML document. For example

< xml version="1.0" encoding="utf-8" >
<hello xmlns="duracellko:hello" xmlns:xs="http://www.w3.org/2001/XMLSchema"></hello>

I would like to remove xmlns and xmlns:xs attributes. I loaded this xml into XmlDocument object and then removes all attributes from DocumentElement. But when I save the XmlDocument, then there is still xmlns attribute in hello element. Can you help me how to remove namespace declarations from XML document.

Thank you

Rasto


Answer this question

Removing xmlns attributes

  • Pinei

    Thank you very much.
    I used overridden WriteStartElement and WriteStartAttribute and it worked.. thx.

  • puso

    Hello, could you please send the code you used to cut those attributes Thank you very much, Lada
  • Jolo

    Namespace is part element name. You have to copy elements to remove them. You can use XSLT (see http://wiki.apache.org/cocoon/RemoveNamespaces) or tweak XmlTextWriter's WriteStartElement and WirteStartAttribute.


  • Aquilax

    I'm sorry, but i don't have source code for problem reported above. I changed the solution in the way, that I removed namespace from all serialized classes.

  • Removing xmlns attributes