Connecting Tech Pros Worldwide Forums | Help | Site Map

Namespacemanager adding default namespace

Vishy
Guest
 
Posts: n/a
#1: Nov 12 '05
Hi

I'm trying to read xml file with namespacemanager; it seems that it
adds up a namespace if there is none; How can avoid this?
so <ID>00589</ID> becomes
<Id xmlns=\"x-schema:#Schema1\">00589</Id>


Thanks

Vishy


Oleg Tkachenko [MVP]
Guest
 
Posts: n/a
#2: Nov 12 '05

re: Namespacemanager adding default namespace


Vishy wrote:
[color=blue]
> I'm trying to read xml file with namespacemanager; it seems that it
> adds up a namespace if there is none; How can avoid this?
> so <ID>00589</ID> becomes
> <Id xmlns=\"x-schema:#Schema1\">00589</Id>[/color]

Namespacemanager can't add namespace, it only helps resolving
namespaces. Provide more info about how do you read your XML.

--
Oleg Tkachenko [XML MVP, MCAD]
http://www.xmllab.net
http://blog.tkachenko.com
Vishy
Guest
 
Posts: n/a
#3: Nov 12 '05

re: Namespacemanager adding default namespace


Thanks for reply; my code goes like this
docMessage is input XML Document; it has 2 namespaces
docOut is output XML document

XmlNamespaceManager nsmanager = new
XmlNamespaceManager(docMessage.NameTable);
nsmanager.AddNamespace("ns1", "http://Authorisation.ContextSchema");
nsmanager.AddNamespace("ns0", "http://Authorisation.RequestSchema");
nsmanager.AddNamespace("", "http://Authorisation.ContextSchema");
XmlNode nodeContext =
docMessage.SelectSingleNode("//ns1:Context",nsmanager);
if (nodeContext != null)
{
docOut.InnerXml =
docMessage.SelectSingleNode("//ns1:Context",nsmanager).OuterXml;
//This is to remove namespace added by namespace manager
docOut.InnerXml = docOut.InnerXml.Replace("
xmlns=\"x-schema:#Schema1\"","");
}

Pascal Schmitt
Guest
 
Posts: n/a
#4: Nov 12 '05

re: Namespacemanager adding default namespace


Hello!
[color=blue]
> XmlNamespaceManager nsmanager = new
> XmlNamespaceManager(docMessage.NameTable);
> nsmanager.AddNamespace("ns1", "http://Authorisation.ContextSchema");
> nsmanager.AddNamespace("ns0", "http://Authorisation.RequestSchema");
> nsmanager.AddNamespace("", "http://Authorisation.ContextSchema");
> XmlNode nodeContext =
> docMessage.SelectSingleNode("//ns1:Context",nsmanager);[/color]

How does the Document loaded into docMessage look like?

[color=blue]
> if (nodeContext != null)
> {
> docOut.InnerXml =
> docMessage.SelectSingleNode("//ns1:Context",nsmanager).OuterXml;[/color]

You select the node twice, better use the nodeContext object here:
[color=blue]
> docOut.InnerXml = nodeContext.OuterXml;[/color]



--
Pascal Schmitt
Vishy
Guest
 
Posts: n/a
#5: Nov 12 '05

re: Namespacemanager adding default namespace


doesn't work either

Vishy

Closed Thread


Similar .NET Framework bytes