Reomoval of name space attribute

Discussion in 'XML' started by davisjoseph@postmark.net, Jun 27, 2005.

  1. Guest

    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
     
    , Jun 27, 2005
    #1
    1. Advertising

  2. 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/
     
    Martin Honnen, Jun 27, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ding feng
    Replies:
    2
    Views:
    2,853
    ding feng
    Jun 25, 2003
  2. Shuo Xiang

    Stack space, global space, heap space

    Shuo Xiang, Jul 9, 2003, in forum: C Programming
    Replies:
    10
    Views:
    2,939
    Bryan Bullard
    Jul 11, 2003
  3. Christian Seberino
    Replies:
    21
    Views:
    1,723
    Stephen Horne
    Oct 27, 2003
  4. Ian Bicking
    Replies:
    2
    Views:
    1,056
    Steve Lamb
    Oct 23, 2003
  5. Ian Bicking
    Replies:
    2
    Views:
    752
    Michael Hudson
    Oct 24, 2003
Loading...

Share This Page