Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / May 2008

Tip: Looking for answers? Try searching our database.

Stripping namespace

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Clive Dixon - 14 May 2008 11:09 GMT
Given an XmlNode with namespace (NamespaceURI has a value), I want to be
able to make a clone of it (XmlNode.CloneNode) but without the namespace.
How can I strip the namespace from a node?
Martin Honnen - 14 May 2008 13:14 GMT
> Given an XmlNode with namespace (NamespaceURI has a value), I want to be
> able to make a clone of it (XmlNode.CloneNode) but without the namespace.
> How can I strip the namespace from a node?

If the namespace is different then the new node is a not a clone of the
old node.
What you can do is create a new node in a different namespace
respectively in no namespace:

      XmlDocument doc = new XmlDocument();
      doc.LoadXml(@"<foo xmlns=""http://example.com/ns1""/>");
      XmlNode foo1 = doc.DocumentElement;
      XmlNode foo2 = doc.CreateNode(foo1.NodeType, foo1.LocalName, "");
      doc.ReplaceChild(foo2, foo1);

Note that if the old node has any child elements then you need to apply
the same approach to the child elements as well as those inherit the
namespace.
Signature


    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.