Alexander ,
The namespace references are not "added". They are a vital part of the
infoset of the document from which you select. They are a part a of the
nodes you select, without them they would be different elements.
Now what exactly do you want? Do you really want elements that do no belong
to any namespace or do you not want the namespace repeated on every element
you selected?
If you want to strip the namespace definitions after you selected the nodes,
you have two options. First, you can create a new document, iterate over the
nodes you selected and and add nodes to the new document with the same names
and content as the ones you selected, but without the namespaces. Second,
you can do this via XSLT ins tead of selecting the nodes and iterating over
the results. Once you went through this step then the nodes in the newly
created doc do not belong to any namespace.
If you just don't want the namespace definition on every node then you need
have parent node that contains the selected nodes. The parent can declare
the namespace as the default namespace or define a prefix that will be used
to indicate the namespace in which the elements are defined.
Did this help clear thing up? If you could post what you are actually trying
to accomplish and why you don't want the namespace definitions maybe we
could give more detailed advice.
HTH,
Christoph Schittko
Software Architect, .NET Mentor
MS MVP XML .NET
[quoted text, click to view] "Alexander Gnauck" <gnauck@ag-software.de> wrote in message
news:bi888j$ej5$07$1@news.t-online.com...
> Hello,
>
> i have problems with the Namespaces and the .Net XML Parser
> My XML looks like this:
>
> <query xmlns="jabber:iq:roster">
> <item jid="srlee@localhost" name="srlee"
> subscription="both"><group>contacts</group></item>
> <item jid="tlee@localhost" name="Troy"
> subscription="both"><group>contacts</group></item>
> <item jid="bglee@localhost" name="Barry"
> subscription="both"><group>contacts</group></item>
> <item jid="dslee@localhost" name="Debbie"
> subscription="both"><group>contacts</group></item>
> </query>
>
> Now i select nodes with SelectNodes. Sometimes i change or add some
> attributes to the selected node. The XML is located in a normal
> XmlDocument Object (doc).
>
> XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
> nsmgr.AddNamespace("foo", "jabber:iq:roster" );
> XmlNode nItem = doc.SelectSingleNode(
> "//foo:item[@jid='srlee@localhost']", nsmgr );
>
> Now when i look at the OuterXml of the selected node i get the
> following:
>
> <item jid="srlee@localhost" name="srlee" subscription="both"
> xmlns="jabber:iq:roster"><group
> xmlns="jabber:iq:roster">contacts</group></item>
>
> The parser adds the Namespace to every tag. Thats very very bad for my
> applciation. I wanna have the raw XM here. Is there a way to get this
> node without the added namespaces? In the old COM MSXML 2-4 parsers i
> never had this problems. Is there a way to tell the parser to handle the
> namespaces like normal attribbutes? Or to ignore them? They make me only
> trouble. Has anybody a idea or similar problems ?
>
> Thanx Alex
>
> --
> AG Software
> Alexander Gnauck
> Wiesental 3
> 74182 Obersulm
> gnauck(at)ag-software.de
>
http://www.ag-software.de >
>