469,332 Members | 6,649 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,332 developers. It's quick & easy.

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

Nov 12 '05 #1
4 4274
Vishy wrote:
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>


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
Nov 12 '05 #2
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\"","");
}

Nov 12 '05 #3
Hello!
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);
How does the Document loaded into docMessage look like?

if (nodeContext != null)
{
docOut.InnerXml =
docMessage.SelectSingleNode("//ns1:Context",nsmanager).OuterXml;
You select the node twice, better use the nodeContext object here:
docOut.InnerXml = nodeContext.OuterXml;


--
Pascal Schmitt
Nov 12 '05 #4
doesn't work either

Vishy

Nov 12 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by surrealtrauma | last post: by
34 posts views Thread by Adam Hartshorne | last post: by
reply views Thread by Martin | last post: by
5 posts views Thread by Water Cooler v2 | last post: by
1 post views Thread by Bruce Sandeman | last post: by
3 posts views Thread by =?Utf-8?B?QWxleGFuZGVyIFd5a2Vs?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by haryvincent176 | last post: by
reply views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.