attributes.remove

B

Bjoern Hoehrmann

* (e-mail address removed) wrote in comp.text.xml:
In my C# program I execute an attributes remove to remove all
attributes in the following root node.

<xtvd xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:TMSWebServices">

All attributes are removed EXCEPT

xmlns="urn:TMSWebServices"

What am I doing wrong or is there a workaround?

The "xmlns" attribute (as well as xmlns:* attributes) are special
attributes that declare the default namespace and namespace pre-
fixes. In the example above you have an element 'xtvd' in the
'urn:TMSWebServices' namespace, if you remove the xmlns "attribute"
you would essentially rename the element, so that's what you would
have to do in order to get rid of them. That's typically not very
useful though, applications would no longer recognize the elements
in the document.
 
S

Sam Stamport

I understand what you are saying.

The odd thing is that when I leave any attributes in the root node, I
cannot read any of the elements or attributes in the XML file using
XPathNavigator/XPathNodeIterator. When I manually remove everything in
the root node except the name <xtvd> everything works just fine.

I am using C# with Visual Studio 2003. Maybe there's something quirky
about .NET?

I cannot find a rename method. Is there some other way I can work
around this problem?
 
B

Bjoern Hoehrmann

* Sam Stamport wrote in comp.text.xml:
I understand what you are saying.

The odd thing is that when I leave any attributes in the root node, I
cannot read any of the elements or attributes in the XML file using
XPathNavigator/XPathNodeIterator. When I manually remove everything in
the root node except the name <xtvd> everything works just fine.

You need to use an XmlNamespaceManager here, declare a prefix for the
xmlns="urn:TMSWebServices" namespace and use namespace prefixes in the
XPath expressions, so instead of "/xtvd" you would use "/prefix:xtvd".

http://www.google.com/search?q=+site:msdn.microsoft.com+XmlNamespaceManager
lists various articles on this subject.
 

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

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,111
Latest member
VetaMcRae
Top