Connecting Tech Pros Worldwide Help | Site Map

Namespacemanager adding default namespace

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 12th, 2005, 04:08 AM
Vishy
Guest
 
Posts: n/a
Default Namespacemanager adding default namespace

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


  #2  
Old November 12th, 2005, 04:08 AM
Oleg Tkachenko [MVP]
Guest
 
Posts: n/a
Default 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
  #3  
Old November 12th, 2005, 04:08 AM
Vishy
Guest
 
Posts: n/a
Default 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\"","");
}

  #4  
Old November 12th, 2005, 04:08 AM
Pascal Schmitt
Guest
 
Posts: n/a
Default 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
  #5  
Old November 12th, 2005, 04:09 AM
Vishy
Guest
 
Posts: n/a
Default Re: Namespacemanager adding default namespace

doesn't work either

Vishy

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.